Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
97 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 DirectX Graphics
 Basic Application
 Drawing Triangles
 Indexed Triangles
 Adding Texture
 Full Screen
 Graphics


 Get the source
 Printable version

 


Full Screen Graphics

Okay, windowed programs are great, but most games run full screen. Full screen is not tough at all. All you have to do is build the correct D3DPRESENT_PARAMETERS structure before you call CreateDevice.

D3DPRESENT_PARAMETERS present; ZeroMemory(&present, sizeof(present)); present.SwapEffect = D3DSWAPEFFECT_FLIP; present.Windowed = FALSE; present.BackBufferFormat = d3ddm.Format; present.BackBufferWidth = d3ddm.Width; present.BackBufferHeight = d3ddm.Height; present.EnableAutoDepthStencil = TRUE; present.AutoDepthStencilFormat = D3DFMT_D16; present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; present.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

Here we see that we change the swap effect to flip so that we are page flipping instead of copying the back buffer. You can continue to copy if you wish.

The back buffer now requires a height and width. We also set the refresh rate and the presentation speed, which is how often to page flip.

You can exit the example by pressing Alt+F4.

Shaders

One could write a book on shaders and barely scratch the surface of their power. In DX8, shaders come in two varieties: vertex and pixel.

Vertex shaders, of course, operate on vertices. You can change position, color, texture coordinate, or any other property of a vertex. This is great for all kinds of procedural effects.

Pixel shaders operate on pixels and can do all kinds of texture blending, noise generation, or anything else you can think of.

Shaders do come at a price. They can get expensive if they are complex. But every vertex and pixel passes through a shader at some point, even if the shader is simple. The call you made to SetVertexShader above did just that. Those shaders are simple, and since they are so common, have been optimized.

A shader script is simply a text file written in a sort of assembly language. Microsoft made no attempt to make it readable, and may result in write-only code (code that even you can’t read after you have written it), if you are not careful. The Microsoft documentation has some errors in it, so use it as a guideline rather than a rule. I highly recommend using MFCPixelShader and ShaderCity for shader testing purposes.

Video Playback

The Microsoft engineers added the DirectShow API to the main DirectX runtime. There is an interface, IDDrawExclModeVideo, that is supposed to coordinate between DirectShow and exclusive mode apps, but it requires a DirectDraw surface. As you may recall, DX8 has removed DirectDraw.

It is possible for a video to play while an IDirect3DDevice8 interface is running, so it doesn’t seem like you need to query for a DirectDraw interface. This awkward scenario is a big oversight of the DirectX developers.

Another oddity is that the DirectShow libraries needed to play video must be built by hand. In previous versions of DirectX Media, the DirectShow libraries (the "Base Classes") included source code as well as the .LIBs needed to link. In DX8, the Base Classes are moved to the Samples folder, and no .LIBs are included. Microsoft does include a VC6 workspace to build these, but you may run into difficulties if you have other SDKs installed (Platform SDK, previous DX Media, etc.).

Conclusion

DirectX 8 Graphics are awesome. The rest of DirectX would do well to follow its lead, especially DirectShow. The most glaring problem with DirectX Graphics is its lack of an existing extension mechanism, like OpenGL’s glGetString. Otherwise, it is an incredibly mature API, one that I look forward to using for some time. This was simply an introduction, and there is much more to be discovered.

I’d love to hear what people have to say. Drop me a line at tjones@hot-shot.com.

A note on the examples

The examples were built and tested with DirectX 8. When textures and video files were needed, files from the SDK were used. All six examples are included in the sample workspace. There may be some minor changes in order to build with your configuration.