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.