• Advertisement
Sign in to follow this  

Beginning D3D rendering triangle

This topic is 3391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry for the general question, but I have been trying to draw a triangle to the screen and nothing shows up. As far as I know, I have included all the steps, as mentioned in the book: DirectX 9 Graphics. After the window is created, I initialize Direct3d and fill a vertex buffer. Every frame, I attempt to draw the primitive, though nothing happens. My Initialization code is this: { // Init D3D - create object and Device CUSTOMVERTEX vertices[] = { {150.0f, 50.0f, 0.5f, D3DCOLOR_XRGB (255,0,255),}, {250.0f, 250.0f, 0.5f, D3DCOLOR_XRGB (255,0,255),}, {50.0f, 250.0f, 0.5f, D3DCOLOR_XRGB (255,0,255),}, }; // Create vertex buffer if( FAILED( m_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) ) { return Failed_CreateVBuffer; } VOID* pVertices = NULL; if (FAILED(m_pVB->Lock(0,sizeof(vertices),(void**)&pVertices, 0 ))) { return Failed_VBLock; } memcpy (pVertices, vertices, sizeof(vertices)); m_pVB->Unlock(); // Turn on the zbuffer m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); // Turn on ambient lighting m_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff ); // Turn off culling, so we see the front and back of the triangle m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // Turn off D3D lighting, since we are providing our own vertex colors m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); } Next, this called every frame: { if (NULL == m_pd3dDevice) {return false;} int r=0; int b=0; int g=0; // Clear Back Buffer m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(r,g,b), 1.0f, 0 ); // Set up Transform, View, and Projection matrices D3DXMATRIX mat_transform; //D3DXMatrixIdentity(&mat_transform); m_pd3dDevice->SetTransform (D3DTS_WORLD, &mat_transform); D3DXVECTOR3 vEyePt( 0.0f, -5.0f,-0.0f ); D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f ); D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f ); D3DXMATRIX mat_view; D3DXMatrixLookAtLH( &mat_view, &vEyePt, &vLookatPt, &vUpVec ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &mat_view ); D3DXMATRIX mat_proj; D3DXMatrixPerspectiveFovLH( &mat_proj, D3DX_PI/4, 1.0f, 1.0f, 100.0f ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &mat_proj ); // Begin the scene if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { if (FAILED (m_pd3dDevice->SetStreamSource (0, m_pVB, 0, sizeof(CUSTOMVERTEX)))) MessageBox (m_hWnd, "ERRORS","",MB_OK); if (FAILED (m_pd3dDevice->SetFVF (D3DFVF_CUSTOMVERTEX))) MessageBox (m_hWnd, "ERROR","",MB_OK); if (FAILED(m_pd3dDevice->DrawPrimitive (D3DPT_TRIANGLELIST, 0, 1))) MessageBox (m_hWnd, "ERROR","",MB_OK); // End the scene m_pd3dDevice->EndScene(); } m_pd3dDevice->Present(NULL,NULL,NULL,NULL); return true; } Again, sorry if this is a vague question, but I have no Idea why nothing is being drawn. Thanks in advance for any help, Jacob.

Share this post


Link to post
Share on other sites
Advertisement
The only thing I can see that is suspect is this:



CUSTOMVERTEX vertices[] =
{
{150.0f, 50.0f, 0.5f, D3DCOLOR_XRGB (255,0,255),},
{250.0f, 250.0f, 0.5f, D3DCOLOR_XRGB (255,0,255),},
{50.0f, 250.0f, 0.5f, D3DCOLOR_XRGB (255,0,255),},
};


...

D3DXVECTOR3 vEyePt( 0.0f, -5.0f,-0.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );





I don't think your camera is looking at the triangle.

This might help, although I usually find that you can't see anything due to a combination of different issues.



D3DXVECTOR3 vEyePt( 0.0f, 0.0f,-5.0f );
D3DXVECTOR3 vLookatPt( 150.0f, 150.0f, 0.5f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );





This places the camera 5 units away from the triangle, looking directly at it.

Hope this helps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement