(Beginner) DirectX screen draw problem

Started by
1 comment, last by Eric Burnett 19 years, 6 months ago
I am trying to make tetris to teach myself directX, but at the moment I cannot get my program to draw the squares to the screen. I can wipe the screen, and write text to it, but the tris just do not show up. I have set
m_d3dEnumeration.AppUsesDepthBuffer = FALSE;

and my render function looks like:
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Called once per frame, the call is the entry point for 3d
//       rendering. This function sets up render states, clears the
//       viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::Render()
{
    Blocks& mainDisplay = *p_mainDisplay;                        //To get around error C2059


    m_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
    // Begin the scene
    if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
    {
        // Set up texture stage states for the background
        m_pd3dDevice->SetTexture( 0, tileTexture );
        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
        m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );

        // Passing an FVF to IDirect3DDevice9::SetFVF specifies a legacy FVF with stream 0.
        m_pd3dDevice->SetFVF(CUSTOMFVF);

        // Tell device location of vertex and index buffers
        m_pd3dDevice->SetStreamSource( 0, vertexBuffer, 0, sizeof(VERTEX) );
        m_pd3dDevice->SetIndices( indexBuffer ); // New in DX9 - takes only 1 parameter

// Draw using Indexed primative (with that new buffer)
        m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 
                                            0, 0, mainDisplay.getLengthOfVertexBuffer(),
                                            0,mainDisplay.getLengthOfIndexBuffer() / 2 );

        // Output statistics
        m_pFont->DrawText( 2, 0, D3DCOLOR_ARGB(255,255,255,0), m_strFrameStats );
        m_pFont->DrawText( 2, 20, D3DCOLOR_ARGB(255,255,255,0), m_strDeviceStats );


        m_pFont->DrawText( 2, 40, D3DCOLOR_ARGB(255,255,255,0), output.c_str() );


        // End the scene.
        m_pd3dDevice->EndScene();
    }
    return S_OK;
}

I have also setup a realtime debug output to my screen (since you cannot use the debug configuration with visual C++ 6.0), and I get the results:
965.65 fps (800x600), X8R8G8B8
HAL (pure hw vp): HIGHTECH EXCALIBUR RADEON 9600
IndexBuffer: 0, 1, 2, 0, 2, 3, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 13, 14, 12, 14, 15
Length of VertexBuffer: 16
VertexBuffer[0]: x=0.175 y=0.3333 z=0 tu=0. tv=0.
VertexBuffer[1]: x=0.2 y=0.3333 z=0 tu=0.1429 tv=1.
VertexBuffer[2]: x=0.2 y=0.3367 z=0 tu=0.1429 tv=1.
VertexBuffer[2]: x=0.175 y=0.3367 z=0 tu=0. tv=1.

I am stumped with this. There should be no lighting issues because it does not use the depth buffer, same for matrix issues, and the tris look to be drawing in the correct order. The oddest part is that when I disable the window clearing, shrink it, and then enlarge it again, part of the corruption that shows up is my texture!!! And not just the first part of it, but the entire thing. I don't see how the one buffer could be bleeding into the other in the vid card unless I copied some memory wrong, but I really have no idea. If you wish, you can get my entire source file here. Thank you! Note: A lot of my code is based upon the source from the book Beginning Direct3D Game Programming, and I am just using it to learn.
--Eric BurnettI know I have mnemophobia, but I can't remember what it is.
Advertisement
There's a lot of issues that could interfere:

a) Check ALL return values (esp. from DrawPrimitiveUP.

b) Enable the DirectX debug output and crank up output to the highest value.

c) Turn of lighting (by setting the renderstate, depth buffer is an entirely different thing).

d) Set the clear color to red or magenta, not black. If you see your squares in black then you know it's not completely off.

e) set culling to none, maybe the faces are in the wrong order.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

--e) set culling to none, maybe the faces are in the wrong order.

Ahh, thank you! I guess I was wrong about the orders. I keep getting confused. I take it this is correct now?


Thanks for the help. Some of those solutions didn't help here, but will be good to remember the next time something (read: I) screw up.
--Eric BurnettI know I have mnemophobia, but I can't remember what it is.

This topic is closed to new replies.

Advertisement