Getting the Project Rendering


I know you want to get to the fancy 3D graphics being rendered. Doesn't everyone? Even in the wonderful world of game development, you need to learn to walk before you can run (as they say). If you recall from earlier, you declared some variables to keep track of the amount of vertices and faces rendered. This part needs to be reset each frame, so add the code from Listing 11.5 to your OnFrameMove method.

Listing 11.5. The Heart of the "Game Loop"
 #if (DEBUG) // Reset the rendering variables in debug mode numberVerts = 0; numberFaces = 0; #endif if (FrameworkTimer.IsStopped)     return; // Nothing to do 

Notice that the first thing to do is reset your counters for the number of vertices and frames you've rendered. You haven't actually started rendering anything yet, so it isn't that big of a deal right now, but better to remember it now than forget it later. You also bail out of the call completely if the timer isn't running because there wouldn't be anything to do.

You haven't quite arrived at the point where you are ready to do much (or render much), but you will at the very least need to add code to clear out the render target. Add the code in Listing 11.6 to your OnFrameRender method.

Listing 11.6. Basic Rendering
 bool beginSceneCalled = false; // Clear the render target and the zbuffer device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, 0, 1.0f, 0); try {     device.BeginScene();     beginSceneCalled = true;     #if (DEBUG)     // Show debug stats (in debug mode)     debugFont.DrawText(null, sampleFramework.FrameStats,         new System.Drawing.Rectangle(2,0,0,0),         DrawTextFormat.NoClip, unchecked((int)0xffffff00));     debugFont.DrawText(null, sampleFramework.DeviceStats,         new System.Drawing.Rectangle(2,15,0,0),         DrawTextFormat.NoClip, unchecked((int)0xffffff00));     // Draw the number of vertices and face information     debugFont.DrawText(null, string.Format         ("\r\nNumber Of Vertices Rendered: {0}\r\nNumber of Faces Rendered: {1}"         ,numberVerts, numberFaces), new System.Drawing.Rectangle(2,30,0,0),         DrawTextFormat.NoClip, unchecked((int)0xffffffff));     #endif } finally {     if (beginSceneCalled)         device.EndScene(); } 

Aside from the updated code to handle drawing the number of frames rendered, this code does the same as the game code for Blockers. Running your basic game framework now will show you a black screen with a frame rate informing you that you're currently rendering zero vertices and zero faces.



Beginning 3D Game Programming
Beginning 3D Game Programming
ISBN: 0672326612
EAN: 2147483647
Year: 2003
Pages: 191
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net