• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Index buffer help very much needed

## Recommended Posts

Starwolf    122
ok, I have this problem with getting my index buffer to display properly on screen, it seems to use the totally wrong vertex coords.
  int iNumVertices = (iResX+1) * (iResY+1); int iNumFaces = iResX * iResY * 2; int iNumIndices = iResX * 6 * iResY; // // Create vertex buffer if( FAILED( pDevice->CreateVertexBuffer( iNumVertices * sizeof(MAPCUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_MAPCUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB ) ) ) return E_FAIL; // // If lock succeeds, copy vertex array to the vertex buffer and unlock vertex buffer MAPCUSTOMVERTEX *pVertices; if(FAILED( g_pVB->Lock( 0, 0, (BYTE**)&pVertices, 0)))return E_FAIL; // // Fill vertex array with positon,color and normal information for (z=0; zUnlock(); // // Create index buffer if( FAILED( pDevice->CreateIndexBuffer( iNumIndices * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_IB ) ) ) return E_FAIL; // // Lock index buffer WORD* pIndices; if( FAILED( g_IB->Lock( 0, 0,(BYTE**)&pIndices,0))) return E_FAIL; // // Fill index list for (y=0; yUnlock(); // /* This bit is from the function being called every frame */ pDevice->SetStreamSource( 0, g_pVB, sizeof(D3DFVF_MAPCUSTOMVERTEX) ); pDevice->SetIndices( g_IB, 0 ); pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, (iResX+1)*(iResY+1), 0, iResX*iResY*2); 
This is the log from my program, showing what I belive to be correct vertex and index data: ------------------------------------------------------ CDFMap constructor, iResX=1, iResY=1 iNumVertices: 4 iNumFaces: 2 iNumIndices: 6 pVertices[0] = {0, 0, 0} pVertices[1] = {1, 0, 0} pVertices[2] = {0, 0, 1} pVertices[3] = {1, 0, 1} pIndices[0] = 0 pIndices[1] = 2 pIndices[2] = 1 pIndices[3] = 2 pIndices[4] = 3 pIndices[5] = 1 DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2) DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 4, 0, 2) .... etc ------------------------------------------------------ Also, I get this when I run the app: "Direct3D8: (INFO) :Failed to create driver indexbuffer", but I dont think it's related because I get the same error while running the DirectX samples in debug mode, and their index buffers work fine. If you see some mistake I've made, don't hesitate to point it out to me! Any help on this would be very very much appreciated, I'm so stuck atm. Edit: I've included a screenshot, available from below. It shows one of the 2 triangles being drawn incorrectly. The 2 triangles in the bottom left corner I made in photoshop to illustrate how it's supposed to look, while the big triangle in the center of the screen is the one actually drawn. One more thing: As I rotate the primitives, rendered using the index buffer, I get alot of flicker on the triangles. Screenshot of problem Edited by - Starwolf on January 12, 2002 9:11:46 AM

##### Share on other sites
At first look, have you set the vertex shader? Add it somewhere where you are setting the vertex stream source. Don''t know if that would be the problem, however.

##### Share on other sites
Starwolf    122
Thanks for the reply. I had the vertex shader set, but had removed it for testing. Same result with it or withouth it :/

##### Share on other sites
Check your projection, view, and world transformations. Also, it may be the depth buffer.

Jim

##### Share on other sites
Starwolf    122
The ships on the linked image is being drawn correctly (they are meshes loaded from .x files), so I suppose my projection, view, world transformations and depth buffer should be okay I guess.. or is that not a given?