Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rendering in C# .NET

Started by gamma_strahler Mar 20, 2007 at 7:38 AM 2 replies 1.1k views
Original Post
gamma_strahler
gamma_strahler
Hello, í´m trying to write a simple level editor in C#. I use Direct3D for rendering. I looked at a lot of examples for Direct3D in C#, and i noticed, that the rendering code is always called from Paint events. This is strange for me, since i used to program in raw C++ before, and therefore called my rendering stuff from the main loop, when no events are pending, and not in response to any events. Can i also use such an "idle event" to do my rendering stuff in .NET? thanks Gamma_strahler
dave
dave
You can do this. The main loop in my application was like this:

		[STAThread]		static void Main()		{			Application.EnableVisualstyles();			Application.SetCompatibleTextRenderingDefault(false);			// Instantiate the form			MainForm form = new MainForm();			using (form)			{				form.Show();				// Main loop				while (form.Created)				{					form.Render();					Application.DoEvents();				}			}		}


This was a basic shader editor i was working on and it had a live preview window.

form.render() called my renderers render() function in turn.
remigius
remigius
This old thread here describes the managed version of the OnIdle loop. Dave's loop should work just fine as well though, both *should* be more efficient than using OnPaints since they don't generate events to drive the loop. ZMan did some more research on the performance of various loops, but I can't find the exact outcome atm.

Hope this helps :)
stanlo
stanlo
Using the previously mentioned OnIdle event has always worked for me, and is what the DXMUT samples use.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.