Lang: DirectX, C++
Compiler: VS2005
I'm currently trying to draw a two sided pyramide (just two triangles connecting and 2 indices). Here is a picture of the pyramide I'm trying to draw.
The vertices that I have set are:
Vertex* vertices;
g_hTriangle->Lock(0, 0, (void**)&vertices, 0);
vertices[0] = Vertex( 0.0f, 0.0f,-2.0f);
vertices[1] = Vertex(-2.0f, 0.0f, 0.0f);
vertices[2] = Vertex( 0.0f, 2.0f, 0.0f);
vertices[3] = Vertex( 2.0f, 0.0f, 0.0f);
g_hTriangle->Unlock();
and the indices I have set are:
WORD* indices;
g_hIndexBuffer->Lock(0, 0, (void**)&indices, 0);
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
g_hIndexBuffer->Unlock();
The problem is that for some reason the Display() isn't able to draw the two connecting triangles at their indices. Here is the code for the with all the Setup() and Display() functions.
Setup()
bool Setup() {
g_hDevice->CreateVertexBuffer(4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, Vertex::FVF, D3DPOOL_MANAGED, &g_hTriangle, 0);
g_hDevice->CreateIndexBuffer(2 * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_D16, D3DPOOL_MANAGED, &g_hIndexBuffer, 0);
Vertex* vertices;
g_hTriangle->Lock(0, 0, (void**)&vertices, 0);
vertices[0] = Vertex( 0.0f, 0.0f,-2.0f);
vertices[1] = Vertex(-2.0f, 0.0f, 0.0f);
vertices[2] = Vertex( 0.0f, 2.0f, 0.0f);
vertices[3] = Vertex( 2.0f, 0.0f, 0.0f);
g_hTriangle->Unlock();
WORD* indices;
g_hIndexBuffer->Lock(0, 0, (void**)&indices, 0);
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
g_hIndexBuffer->Unlock();
D3DXVECTOR3 position(0.0f, 5.0f, -8.0f);
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX view;
D3DXMatrixLookAtLH(&view, &position, &target, &up);
g_hDevice->SetTransform(D3DTS_VIEW, &view);
D3DXMATRIX projection;
D3DXMatrixPerspectiveFovLH(&projection, D3DX_PI * 0.5f,
(float)g_nBufferWidth/(float)g_nBufferHeight, 1.0f, 1000.0f);
g_hDevice->SetTransform(D3DTS_PROJECTION, &projection);
g_hDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
return true;
}
Display()
bool Display(bool frame_rate) {
if(g_hDevice) {
g_hDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
g_hDevice->BeginScene();
g_hDevice->SetStreamSource(0, g_hTriangle, 0, sizeof(Vertex));
g_hDevice->SetIndices(g_hIndexBuffer);
g_hDevice->SetFVF(Vertex::FVF);
g_hDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 6);
g_hDevice->EndScene();
g_hDevice->Present(0, 0, 0, 0);
}
else
return false;
return true;
}
Thank you ahead of time for your help.