000
01.10.2006, 14:18 Uhr
~Monixus
Gast
|
Hi, ich möchte gerne anhand von Indizies ein Würfel auf den Bildschirm bringen, das klappt allerdings nicht so richtig.
Hier mal mein Code, evtl. sieht da jemand einen Fehler:
Initialisierung des Index/Vertexbuffer
C++: |
g_pD3DDevice->CreateVertexBuffer(8 * sizeof(Vertex), 0, D3DFVF_DIFFUSE | D3DFVF_XYZ | D3DFVF_TEX1, D3DPOOL_MANAGED, &g_pVertBuff, NULL);
g_pD3DDevice->CreateIndexBuffer(36, 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &g_pIndexBuff, NULL);
Vertex* pVertices; WORD* pIndices;
g_pVertBuff->Lock(0, 0, (void**) (&pVertices), D3DLOCK_NOSYSLOCK); g_pIndexBuff->Lock(0, 0, (void**) (&pIndices), D3DLOCK_NOSYSLOCK);
D3DVECTOR vTemp; vTemp.x = -1.0f; vTemp.y = 1.0f; vTemp.z = -1.0f; pVertices[0].vPosition = vTemp; vTemp.x = -1.0f; vTemp.y = 1.0f; vTemp.z = 1.0f; pVertices[1].vPosition = vTemp; vTemp.x = 1.0f; vTemp.y = 1.0f; vTemp.z = 1.0f; pVertices[2].vPosition = vTemp; vTemp.x = 1.0f; vTemp.y = 1.0f; vTemp.z = -1.0f; pVertices[3].vPosition = vTemp; vTemp.x = -1.0f; vTemp.y = -1.0f; vTemp.z = -1.0f; pVertices[4].vPosition = vTemp; vTemp.x = -1.0f; vTemp.y = -1.0f; vTemp.z = 1.0f; pVertices[5].vPosition = vTemp; vTemp.x = 1.0f; vTemp.y = -1.0f; vTemp.z = 1.0f; pVertices[6].vPosition = vTemp; vTemp.x = 1.0f; vTemp.y = -1.0f; vTemp.z = -1.0f; pVertices[7].vPosition = vTemp;
pVertices[0].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[0].u = -1.0f; pVertices[0].v = 1.0f; pVertices[1].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[1].u = -1.0f; pVertices[1].v = 1.0f; pVertices[2].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[2].u = -1.0f; pVertices[2].v = 1.0f; pVertices[3].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[3].u = -1.0f; pVertices[3].v = 1.0f; pVertices[4].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[4].u = -1.0f; pVertices[4].v = 1.0f; pVertices[5].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[5].u = -1.0f; pVertices[5].v = 1.0f; pVertices[6].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[6].u = -1.0f; pVertices[6].v = 1.0f; pVertices[7].color = D3DCOLOR_XRGB(255, 255, 0); pVertices[7].u = -1.0f; pVertices[7].v = 1.0f;
int aiIndex[36] = {0, 3, 7, 0, 7, 4, // Vorderseite 2, 1, 5, 2, 5, 6, // Hinterseite 1, 0, 4, 1, 4, 5, // Linke Seite 3, 2, 6, 3, 6, 7, // Rechte Seite 0, 1, 2, 0, 2, 3, // Oberseite 6, 5, 4, 6, 4, 7}; // Unterseite
for(int i = 0; i < 36; i++) { pIndices[i] = (WORD) aiIndex[i]; }
g_pVertBuff->Unlock(); g_pIndexBuff->Unlock();
|
Zeichnen in meine Renderfunktion
C++: |
//Buffer clearen und Hintergrundfarbe setzen g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
//Start des Zeichnen g_pD3DDevice->BeginScene();
g_pD3DDevice->SetStreamSource(0, g_pVertBuff, 0, sizeof(Vertex)); g_pD3DDevice->SetIndices(g_pIndexBuff);
SetCamera();
//Zeichnen des Dreiecks g_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
g_pD3DDevice->EndScene(); //Sichtbar machen g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
|
Erkennt da jemand etwas. |