Rendering in a CLR Windows Forms application

Started by
1 comment, last by tonypr 16 years, 2 months ago
Hi there, I'm trying to use DirectX in a CLR C++ Windows Forms Application, but I've got one big of a problem: where to put the rendering loop. In a basic Win32 C++ program no problem, you add it to the message loop. In a C# Managed DirectX program, it's quite interesting to see how it works: in the main function you've got: using (Form1 frm = new Form1()) { while(frm.Created) { frm.Render(); Application.DoEvents(); } } And in a C++ CLR program, I don't have a clue. Your form is created as this: Application::Run(gcnew Form1()); But that's it. So what I'm doing right now is that I'm initializing all the DirectX in the Form_Load method and then launch a thread which is basically while(1) Render();. Although it's working, I'm wondering if there's a way to do it in a "cleaner" manner. Thank you.
Advertisement
I personally use Tom Miller's OnApplicationIdle loop, and you should be able to easily invoke the same loop from C++/CLI. I'd recommend against rendering in a seperate thread - depending on which version of DirectX you're using, it might not be supported. There are also other limitation on when you can call Direct3D methods from other threads, so avoiding having to sync the extra thread might save you quite a bit of work.
Sirob Yes.» - status: Work-O-Rama.
Good pointer. Thank you sirob.

This topic is closed to new replies.

Advertisement