Original Post
Hello! I want to set up a DirectX10 render loop in C++/CLI and WinForms to render constantly to a panel. To do this I followed this article, which describes a render loop in Managed DX and WinForms. My code looks like this: Nothing special. I just create my frame, pass the handle (HWND) to initDX10() (which initializes the D3D10 Device and a swap chain), hook the Idle Event and start the application. My OnIdle function looks like this: As long as no message is available I call Render(); To see if this basically works I set up a little test Render method: Now if I run this code I get a frame with a red/green flickering panel as expected (the flickering is really fast). After this test I wrote the real DX10 render function: As you can see this does basically exact the same, except that this time DirectX is used to clear the panel. The problem is: If I run this code the panel still flickers in red/green colors but waaaaay to slow. The flickering pattern goes like this: red for 1s, green for 1s, red for 4s, green for 2s, red for 5s, green for 1s, red for 1s and so on. Sometimes a color is displayed more than 3s seconds! Anyone knows why my DX10 render function doesnt work and how I could fix it? Thanks!
// main
int main(array<System::String ^> ^args) {
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
EditorForm^ f = gcnew EditorForm();
g_hwnd = (HWND)f->panel1->Handle.ToPointer();
initDX10(g_hwnd);
Application::Idle += gcnew EventHandler(f, &EditorForm::OnIdle);
// Create the main window and run it
Application::Run(f);
return 0;
}
void OnIdle(Object^ sender, EventArgs^ e) {
MSG msg;
while(!PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
Render();
void Render() {
static int i=0;
if(i == 0) {
i++;
this->panel1->BackColor = System::Drawing::Color::Red;
}
else if(i == 1) {
i--;
this->panel1->BackColor = System::Drawing::Color::Blue;
}
}
void Render() {
static int i=0;
float ClearColor[4];
if(i == 0) {
ClearColor[0] = 1.0f; ClearColor[1] = 0.0f;
ClearColor[2] = 0.0f; ClearColor[3] = 1.0f;
i++;
}
else if(i == 1) {
ClearColor[0] = 0.0; ClearColor[1] = 1.0f;
ClearColor[2] = 0.0f; ClearColor[3] = 1.0f;
i--;
}
g_d3d10Device->ClearRenderTargetView( g_renderTargetView, ClearColor );
g_swapChain->Present( 0, 0 );
}