# Rendering in C# .NET

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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 :)

##### Share on other sites
Using the previously mentioned OnIdle event has always worked for me, and is what the DXMUT samples use.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628293
• Total Posts
2981870

• 11
• 10
• 10
• 11
• 17