Click to See Complete Forum and Search --> : Why can't a draw A triangle on the screen?


Chambers
July 1st, 2002, 11:57 AM
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 **** is this happening. Do you think the problem is interlinked? I would appreciate any views or links to web sites that deal with this kind of problem. I cannot see where the problem lies at all. I have managed to load a bitmap into an offscreen surface, blit it to the backbuffer and flip it and the image gets displayed, so the problem isn't with that. Anyway, thanks for reading the problem this far, just hope you can take some time to suggest some PC saving ideas, or else PC will be going out the window, Direct3D attached to its BackSIDE.

Alan.

cup
July 2nd, 2002, 04:11 AM
Have you had a look at

http://www.codeguru.com/directx/ddraw_in_mfcwin.html

It may give you some clues on direct draw. I know you don't want the MFC stuff but it is just getting the general feel of how the calls are used. It took me ages working out how to do something without MFC. There are very few non-MFC examples about.

Sorry I couldn't answer your question.

Chambers
July 2nd, 2002, 05:05 AM
Many thanks for your response, I will have a look at the URL in a minute. [I]"Sorry I couldn't answer your question"[\I], don't be. I am extremely pleased that you took the time to read through that lengthy problem and post a URL that may be able to help.

Very Much Appreciated,
Alan.