In this chapter, I review major changes that have been made in XNA 4.0. If you’re familiar with XNA 3.x or other versions, this is a great place to get started in this book. If you’re new to XNA, you should probably skip ahead to the next chapter. You won’t be missing out on anything, as all of the information covered in this chapter will be covered throughout the rest of the book.
The first thing you might notice when creating a game project in XNA 4.0 is that the structure of the solution has changed. In previous versions of XNA, the content pipeline picked up game content from a subfolder named Content, which was located within the game project you created, as seen in Solution Explorer (see Figure 1-1).
In XNA 4.0, the Content folder has been moved to a new project within your solution. The content project will be listed under the name GameProjectNameContent (with the name of your project replacing “GameProjectName”) and will be followed with the word “Content” in parentheses (see Figure 1-2).
You’ll add all your game content (audio, textures, models, etc.) to the content project in the same way you added them to the content folder in XNA 3.x. You will also still use the same code to access the content from the content pipeline, just as you did in XNA 3.x. This move makes working with multiple versions of the same project (e.g., if you built a project for both Windows and Xbox 360) much more user friendly and less confusing.
Just as in previous versions of the XNA Framework, XNA 4.0 is designed for cross-platform development. Developers using XNA 4.0 can write games for Windows, Xbox 360, and now Windows Phone 7 Series. Not only that, but aside from some resource management and screen resolution issues, nearly 100% of the code written for any of those platforms will also work on the other platforms. This gives game developers incredible flexibility to easily create games for each platform.
To learn more about developing games for Windows Phone 7 Series, see Chapter 17.
Between today’s top-of-the-line graphics cards, which support DirectX 10 and higher, the powerful Xbox 360, and the introduction of Windows Phone 7 Series, the XNA Framework supports development on a wide range of devices with different hardware capabilities. In previous versions of XNA, these hardware differences had to be dealt with at runtime, which often led to platform-dependent code. To help facilitate development on these different devices, XNA 4.0 introduces the concept of profiles. These profiles allow developers to target certain hardware devices by supporting a specific set of graphics API designated by the profile they choose.
There are two profiles in XNA 4.0: Reach and HiDef. HiDef is designed for high-powered, top-of-the-line hardware, whereas Reach is designed to support a wider range of hardware devices. The Reach profile offers a limited set of graphic features and is a subset of the HiDef profile. When choosing to write a game using the Reach profile, you sacrifice some of the more powerful graphics API, but you’ll be assured that your game will work on a variety of devices (specifically Windows, Xbox 360 and Windows Phone), assuming those devices meet the minimum specifications for XNA 4.0.
The HiDef profile is designed to support today’s most powerful graphic devices. You can use the HiDef profile to target Xbox 360 hardware as well as Windows-based computers with graphics cards supporting at least DirectX 10.
You can identify which profile is supported by your hardware at
runtime by using the
method. A chart illustrating more detail on the differences
between the Reach and HiDef profiles is shown in Table 1-1.
|Supported Platforms||Windows Phone 7 Series, Xbox 360, and any Windows PC with a DirectX 9 GPU that supports at least shader model 2.0||Xbox 360, and any Windows PC with a DirectX 10 (or higher) GPU|
|Shader Model||2.0 (but Windows Phone does not support custom shaders)||3.0+ (Xbox 360 supports custom shader extensions such as vfetch, which are not available on Windows)|
|Maximum Texture Size||2,048||4,096|
|Maximum Cubemap Size||512||4,096|
|Maximum Volume Texture Size||Volume textures are not supported||256|
|Non Power of Two Textures||Yes, but with limitations: no wrap addressing mode, no mipmaps, no DXT compression on non power of two textures||Yes|
|Non Power of Two Cubemaps||No||Yes|
|Non Power of Two Volume Textures||Volume textures are not supported||Yes|
|Maximum Number of Primitives per Draw Call||65,535||1,048,575|
|Maximum Number of Vertex Streams||16||16|
|Maximum Vertex Stream Stride||25||255|
|Index Buffer Formats||16-bit||16- and 32-bit|
|Vertex Element Formats||Color, Byte4, Single, Vector2, Vector3, Vector4, Short2, Short4, NormalizedShort2, NormalizedShort4||All of the Reach vertex element formats, plus HalfVector2, HalfVector4|
|Texture Formats||Color, Bgr565, Bgra5551, Bgra4444, NormalizedByte2, NormalizedByte4, Dxt1, Dxt3, Dxt5||All of the Reach texture formats, plus Alpha8, Rg32, Rgba64, Rgba1010102, Single, Vector2, Vector4, HalfSingle, HalfVector2, HalfVector4; floating-point texture formats do not support filtering|
|Vertex Texture Formats||Vertex texturing is not supported||Single, Vector2, Vector4, HalfSingle, HalfVector2, HalfVector4|
|Render Target Formats||Call
|Multiple Render Targets||No||Up to 4; must all have the same bit depth; supports alpha blending and independent write masks per render target|
|Separate Alpha Blend||No||Yes|
In previous versions of XNA, the
BasicEffect class was a very basic effect, implemented mainly to allow new
game developers to build games without in-depth knowledge of complex
shader code. The idea was that serious game developers would implement
their own shaders and not rely on the
Much of that thinking had to change with the onset of Windows Phone 7, which does not support custom shaders. As a result, new configurable effects were added, available on both the Reach and HiDef profiles. These are:
BasicEffect class has been tweaked to
include more pixel and vertex shaders to support more realistic
lighting and fog effects.
Some of the state properties that were used in previous versions of XNA to modify the way scenes were drawn on the screen and the way the graphics device processes data sent to it by your game have been moved into state object classes. These classes are:
Scalars in XNA 4.0 allow developers to write their games without worrying about the native resolution or screen orientation. The scalars will automatically scale your desired resolution to the resolution supported by the device on which you’re playing your game. This enhancement dramatically improves game performance.
Screen orientation is most important on Windows Phone 7 devices, which switch rotation from varieties of landscape to portrait and back when the device rotates. The scalars automatically map your game from one orientation to another, and rotate input such as touch panel input accordingly.
namespace contains classes that enable access to multitouch input on
Windows and Windows Phone devices. The namespace adds the
TouchPanel class and
TouchLocation class, which enable access to touch points from input devices
(such as the touch panel in Windows Phone 7 series devices).
A fairly large number of classes and methods have been added or modified. You can view a full list on Microsoft’s MSDN website at http://msdn.microsoft.com/en-us/library/bb417503.aspx.