Rendering in C# .NET

Started by
2 comments, last by stanlo 17 years, 1 month ago
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
Advertisement
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.
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 :)
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Using the previously mentioned OnIdle event has always worked for me, and is what the DXMUT samples use.

This topic is closed to new replies.

Advertisement