In my Render I call Device->BeginScene and then Call Sprite->Begin, but this triggers another WINAPI MsgProc to Draw which kicks me out of my current iteration through Render and back into it again, where Begin Scene fails and my Sprite->Draw never is reached. What can I do to avoid this?
Here is what I have:
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){ switch( msg ) { case WM_DESTROY: d3d.Cleanup(); PostQuitMessage( 0 ); return 0; case WM_PAINT: d3d.Render(); ValidateRect( hWnd, NULL ); return 0; } return DefWindowProc( hWnd, msg, wParam, lParam );}
Then render looks like this:
void Direct3D::Render(){ //------------------- D3DCOLOR vertexColour = 0xFFFFFFFF; //------------------- if ( NULL == d3d.d3d9Device) return; //------------------- d3d.d3d9Device->Clear( 0, // Number of Rectangles in Array - Set to 0 since Rects is NULL NULL, // Pointer to an Array of D3DRect to Clear - NULL indicates entire viewport D3DCLEAR_TARGET, // Surface to Clear D3DCOLOR_XRGB( 0, 0, 0 ), // Clear to this Color 1.0f, // Depth Buffer to Clear to 0 // Stencil Buffer to Clear to ); //------------------- if ( SUCCEEDED( d3d.d3d9Device->BeginScene() ) ) { //------------------- // Scene Rendering takes place Here //------------------- // Draw the triangles in the vertex buffer. This is broken into a few // steps. We are passing the vertices down a "stream", so first we need // to specify the source of that stream, which is our vertex buffer. Then // we need to let D3D know what vertex shader to use. Full, custom vertex // shaders are an advanced topic, but in most cases the vertex shader is // just the FVF, so that D3D knows what type of vertices we are dealing // with. Finally, we call DrawPrimitive() which does the actual rendering // of our geometry (in this case, just one triangle). //------------------- d3d.d3d9Sprite->Begin(NULL); d3d.d3d9Sprite->Draw( d3d.d3dTexture, NULL, new D3DXVECTOR3(128.0f, 128.0f, 0.5f), NULL, vertexColour ); d3d.d3d9Sprite->End(); /* d3d.d3d9Device->SetStreamSource( 0, d3d.d3d9VertexBuffer, 0, sizeof( Vertex ) ); d3d.d3d9Device->SetTexture(0, d3d.d3dTexture); d3d.d3d9Device->SetFVF( D3DFVF_TLVERTEX ); d3d.d3d9Device->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ); */ //------------------- End the Scene d3d.d3d9Device->EndScene(); } //------------------- Present the Backbuffer contents to the display d3d.d3d9Device->Present( NULL, NULL, NULL, NULL); //-------------------}//-------------------
But as I said, I can never complete the iteration through Render due to it firing a new Draw Event. What am I doing wrong here?