Why can't I draw a triangle to the screen?
-
Hi all, I want to draw a mere triangle on the screen using Direct3D and DirectDraw(which is becoming more and more of a pain in the a**e). I have done the following: 1.) Set up my custom window. 2.) Initialised DirectDraw. 3.) Set Cooperative level. 4.) Set Display Mode (1280x1024x16). 5.) Created Primary Surface with 1 Backbuffer. 6.) Obtained an IDirect3D7 pointer using QueryInterface with the DirectDraw pointer. 7.) Used 3D7->CreateDevice(GUID, PS Backbuffer, &D3DDevice7); where the GUID is IID_Direct3DTnLHalDevice as detected by an enumeration function, D3DDevice7 is a pointer to the structure you expect (initialised to NULL). 8.) The viewport is created. None of these initialisation aspects return an error. The app then enters the WindowProc callback function to process any messages. The WindowProc function uses PeekMessage to see if there are any pending messages, if there are NOT it calls the Render() function, which uses the following code to render ONE gouraud shaded triangle: HRESULT CDarkSoldier::Render() { if (SUCCEEDED(m_DXControl.m_pD3DDevice7->BeginScene())) { D3DTLVERTEX v[3]; v[0] = D3DTLVERTEX(D3DVECTOR(160,50,0), 1, D3DRGB(1,0,0), D3DRGB(0,0,0), 0, 0); v[1] = D3DTLVERTEX(D3DVECTOR(440,200,0), 1, D3DRGB(0,1,0), D3DRGB(0,0,0), 0, 0); v[2] = D3DTLVERTEX(D3DVECTOR(160,550,0), 1, D3DRGB(0,0,1), D3DRGB(0,0,0), 0, 0); m_DXControl.m_pD3DDevice7->DrawPrimitive(D3DPT_TRIANGLELIST, D3DVT_TLVERTEX, (LPVOID)v, 3, NULL); return m_DXControl.m_pD3DDevice7->EndScene(); } return S_OK; } However, the screen is blank when my app runs. I have added a MessageBox() function into the BeginScene() block and re-run the code, the messagebox pops up instantly (even when pressed ok), which means this block of code IS being run. I have also used a HRESULT to test the values that come out of DrawPrimitive and EndScene functions, they are both OK (no errors). I have not got a clue why it doesn't work, I have tried flipping the primary surface all to no avail. Also, when my app exists I have the following code: CDApp::~CDApp() { if (m_pD3D) { m_pD3D->Release(); m_pD3D = NULL; } if (m_pDD) { m_pDD->Release(); m_pDD=NULL; } } Strangely enough if I add this: if(m_pD3DDevice) { m_pD3DDevice->Release(); m_pD3DDevice = NULL; } ANYWHERE in the destructor block, the application causes an unhandled exception upon release of the m_pD3DDevice, which has been initialised and is NOT NULL. Why the hell is this happening. Do you think the problem is interlinked? I would appreciate a