XNA 3.0 Game Programming Recipes
Chapter 3: Working with 2D Images/Textures in XNA 3.0 (94 pages)
Whether your game will be 2D or 3D, it will definitely use a vast amount of images. Where 2D games need a whole set of canvas and character images, 3D games use images to cover the triangles that make up their 3D objects.
There are many other cases where you’ll need images while creating a game. Presenting the user with a nice-looking menu interface and saving a screenshot to disk are just some examples. Special 2D images can be required as input to very advanced effects.
This chapter covers how to load, create, show, and manipulate images in XNA. The first recipes are aimed at 2D games because they mainly focus on rendering 2D images to the screen. You’ll also find two recipes that introduce you to the content pipeline, a major component of the XNA Framework. The more advanced recipes show some uses of 2D images in a 3D
game world, supported by HLSL code fragments.
3-1. Display 2D Images: Load and Render Images Using the SpriteBatch Class
This beginner recipe shows how you can easily use XNA’s SpriteBatch to render 2D images to the screen using hardware acceleration.
3-1. Rotate, Scale, and Mirror an Image
Exploring some of the more complex overloads of the SpriteBatch.Draw method, this recipe shows how you can rotate, scale and/or mirror an image before rendering it to the screen.
3-3. Render Transparent Images Using Layers
XNA’s SpriteBatch class supports rendering 2D images to multiple layers, a requirement for creating rich 2D games. This recipe shows you how you can maintain full control when blending multiple 2D images over each other.
3-4. Consider Performance When Using the SpriteBatch Class
This recipe discusses some performance rules you have to keep in mind when creating large 2D applications in XNA.
3-5. Display Text
As simple as it sounds, XNA’s SpriteBatch can also be used to render text to the screen using SpriteFont objects.
3-6. Create a 2D Menu Interface
This recipe discusses from start to finish the steps involved in creating a complete 2D Menu for your game. This includes smooth transitioning from one menu to another, as well as post-processing effects.
3-7. Create a Texture, Define the Color of Each Pixel,
Save a Texture to a File
XNA has made it very easy to define and save an image by means of the Texture2D class.
3-8. Render the Scene into a Texture
This recipe discusses two ways to hijack the content of the video output and save it into a Texture2D object. Pitfalls such as different aspect ratios between the multiple render targets are explained in detail.
3-9. Extend the Image Content Processor
This recipe introduces you to XNA’s Content Pipeline. In this easy recipe, you’ll learn how to manipulate the color content of an image during compile time.
3-10. Extend the Image Content Processor: Grayscale Conversion and Processor Parameters
Extending on the previous recipe, this recipe shows how you can make your Content Processors more flexibly using a feature introduced in XNA 3.0.
3-11. Make Your Scene More Impressive with Billboarding: Render 2D Images in a 3D World So They Always Face the Camera
Billboarding is one of the most powerful and most used techniques used in 3D games. Therefore, it is discussed in a lot of detail and in all possible flavours, shown both for CPU and GPU. Billboarding renders 2D images in a 3D world, so they are always facing the camera. On larger distances, this e.g. allows you to create a convincing forest in your 3D world using only 2D images.
3-12. Create a 3D Explosion Effect/Simple Particle System
Using the billboarding technique created in the previous recipe, this recipe introduces you to HLSL particle systems. As an example, you learn how to invoke a full-blown 3D explosion at a 3D location of your choice.
3-13. Create a Mirror: Projective Texturing
Creating a mirror requires some mathematical steps, but the results can be convincing. This recipes helps you through the difficult parts.
Recipe 3-12: HLSL Particle effect making extensive use of Billboarding to create a 3D explosion.
- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans