Sign in to follow this  
gamma_strahler

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this