1. Beginning Direct3D Game Programming:
Window Game Programming
Foundation
jintaeks@gmail.com
Division of Digital Contents, DongSeo University.
November 2016
2. Contents at a Glance
Chapter 1 The History of Direct3D/DirectX Graphics
Chapter 2 Overview of HAL and COM
Chapter 3 Programming Conventions
Chapter 4 3D Fundamentals, Gouraud Shading,
and Texture-Mapping Basics
Chapter 5 The Basics
- Setup Environment, DirectX Basics
Chapter 6 First Steps to Animation
Chapter 7 Texture-Mapping Fundamentals
Chapter 8 Using Multiple Textures
Chapter 9 Shader Programming with the High-Level Shader Language
Chapter 10 More Advanced Shader Effects
Chapter 11 Working with Files
Chapter 12 Using Mesh Files
2
3. Window Game Programming
Foundation
A game programmer mainly needs to know three topics for
Windows programming:
• How to create a window
• How to use the window message procedure
• How to use resources (icons, menus, shortcuts, and so on) with
the help of Visual C/C++
3
4. How Windows Interacts with Your Game
A Windows-based game has to wait until it is sent a message
by Windows.
This message is passed to your program through a special
function called by Windows.
Once a message is received, your program is expected to take
an appropriate action.
Messages arrive randomly, so every Windows game has to
check for new messages constantly.
4
6. A Window Skeleton
Develop a Windows application that provides the necessary
features common to all Windows applications.
This Windows program will contain two functions:
• WinMain()
• A window procedure such as WndProc()
6
7. WinMain() function
1. Define a window class.
2. Register that class with Windows.
3. Create a window of that class.
4. Display the window.
5. Begin running the message loop.
7
16. VOID Render()
{
if( NULL == g_pd3dDevice )
return;
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Rendering of scene objects can happen here
// End the scene
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
16
22. Practice: Change clear color
Add a feature:
– Terminate the program when 'Esc' is pressed.
– Modify the message loop with PeekMessage() and call Render() in
message loop.
– Modify the Render() function that the Clear color changes from (0,0,0)
to (0,0,255) exactly in 1 second.
22
This message is passed to your program through a special function called by Windows.
// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.