Reputation: 1259
I developing a simple 3D model viewer on XNA 4.0. Is there a way to avoid a infinite game loop with Draw and Update functions? I need render 3D graphics, but without infinite rendering of scene. I mean I need redraw the scene only then it really changed.
Upvotes: 4
Views: 515
Reputation: 8613
This sort of scenario would be best solved by using WinForms or WPF as the host for your rendering system. I have worked with such systems before and I found using SlimDX with WPF Interop was my preferred solution. Using this approach allows for the addition of nice UI features provided by WPF, overlain on a 3D model rendered to a surface.
Upvotes: 1
Reputation: 9218
You are going to have to roll your own multi-threaded loop; if you stall either Update
or Draw
the other will get stalled too. Another consideration is that if your window gets obscured somehow (under non-DWM environments; a window overlapping it for instance) stalling the Draw
will leave areas of your window unpainted.
If you want to go ahead with this; what you will do is start a Thread
the first time Update
gets called and subsequently use a ManualResetEvent
to synchronise the two.
A far more robust option is to render your entire scene to a RenderTarget2D
when the scene is updated; if the scene has not been altered since the last Update
or Draw
call simply render the RenderTarget2D
instead of the whole scene. This is still an infinite loop, but it tends toward your requirement (even though it does not meet it).
Upvotes: 1
Reputation: 32418
I suggest taking a look at how they're doing it in their samples:
App Hub - WinForms Series 1
App Hub - WinForms Series 2
Upvotes: 4
Reputation: 12608
Why exactly do you want this?
If you use a winforms application you have more control on your update and draw loop, but you also could render the scene to a texture first, and then stop rendering at all.
Upvotes: 2