index > Game Technologies: DirectX 101 > The best way to handle the render loop?

The best way to handle the render loop?

I have been through many tutorials, and have seen many variations doing things a number of different ways- I want to know what is the best way, or preferred way, or "Official Microsoft way", to handle the main render loop specifically for C# and the latest DirectX.

Some use the Application.Idle event handler to call the render method.

Some use the standard Paint method to call the render method, followed immediately by a call to invalidate.

Some use a timer to call the render method.

I have tried all three, and with all three the responsiveness slows down to a crawl with only 100 boxes, and locks up when the keyboard buffer gets full. I am not using DirectInput, I'm using the standard KeyUp and KeyDown events.





Nick Lilavois
Nick Lilavois

Well, it seems the Application.Idle render loop is the preferred way, since Tom Miller calls it his final post on render loops. "Simple, elegant, effective. No extra allocations, no extra collections, it just works.." is his assesment of this approach and I think he's quite right

I don't think there really is an official way to do this, since the way you set up your render loop depends a lot on what you want to do with it. For a tool of mine for example, I only render when the Application.Idle event fires, without the AppStillIdle loop. Since the tool doesn't need 60+ frames per minute, this works out quite well. For typical games or other realtime rendering apps though, I'd go with the Application.Idle & AppStillIdle loop.

You could try using the Window Messages directly (by overriding your Form or Control's WndProc method) instead of using the events to solve your keyboard issues, since Windows Messages are typically much more efficient. However, the events really shouldn't be causing the lockups, so you might want to check if your render loop isn't preventing any messages from getting handled.

For some more suggestions on improving the performance when rendering a lot of small meshes, check this thread on GameDev.net.




http://www.mdxinfo.com - Managed DirectX and Game Programming Resources, too ;)
Rim van Wersch
Generally speaking, the sample framework represents the recommended guidance. Take a look at how the Empty Project (Managed) in the DX SDK handles it.


David Weller [MSFT], Community Manager, Microsoft Game Development Group. http://letskilldave.com
David Weller
reply 3

You can use google to search for other answers

 

More Articles

• Problem while installing Direct X 9.0c
• Video Application
• Error with DirectX
• [MDX] Device errors while using DX SDK sample framework
• View 3D Axis
• Build background out of multiple bitmaps
• directsound
• How good is directx normal calculation
• DXUT with Windows Forms menus.
• ActiveX control not drawing in fullscreen mode -- help!
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Beginner going Mad!!
• Problem loading simple shader
• MDX Sample code doesn't work in my Visua
• DirectDraw: Full Screen App loosing focu
• Drawing a background bitmap as fast as p
• Won't draw primitives
• rendering text to surface problem
• Toggling windowed/fullscreen from an sdi
• How do you play MP3's in DirectSound?
• Basic Help Drawing Graphics
• Games with sound impossible in MDX 2.0
• DirectX engine
• using Microsoft.Samples.DirectX.UtilityT
• Problem in Device Capturing Multiple times
• Rendering based on distance and subsets

Hot Articles

• Just Curious...
• Showing billboard (a cartoon character)
• VB.NET & Direct X
• How not to display debug FPS in videos
• Mesh.Intersect Problem
• MDX, where do I put the symbol files?
• Writing to a EffectsBuffer in MDX 2.0.
• texture coords fromMesh.Intersect
• Problems with DirectDraw
• Dynamic Effects while Playing Direct Sou
• The lights have gone out! Help!
• Unit size
• Games with sound impossible in MDX 2.0
• Combining a Roatation and Translation ma
• Lighting and Rendering

Recommend Articles

• The best way to handle the render loop?
• Where to go?
• Lighting and Rendering
• VertexBuffer weird data
• Cabinet file cannot be trusted....wdf????
• DirectX Capabilities
• DirectX February 2006 SDK has Conflict w
• Erorr in loading DirectX Reference
• how to convert screen co - ordinates to
• Vsync and timer problems
• How do I uninstall DirectX 9c
• Managed Direct3D available to the IE .NE
• IDirectSoundBuffer8::Lock dwFlags parame
• Realistic Movement using Rotation &
• [MDX][C#] SwapChain pain in the rear end