• ### Popular Now

• 9
• 10
• 11
• 13
• 9

#### Archived

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

# Indexed verts

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

## Recommended Posts

I´m trying to use indexed verts to render my terrain. THis is the code I use to load the index with.
		p_iD3DDevice9->CreateIndexBuffer(128*6*128*sizeof(int), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_DEFAULT, &p_iD3DIndexBuffer9,NULL);

short *p_Indices;
p_iD3DIndexBuffer9->Lock( 0,                 //Fill from start of the buffer.

sizeof(short)*128*128, // Size of the data to load.

(VOID**)&p_Indices, // Returned index data.

0 );         // Send default flags to the lock.

for(int y = 0;y < TERRAIN_Z;++y)
{
for(int x = 0;x < TERRAIN_X;++x)
{
*p_Indices++ = x + y * (TERRAIN_X + 1);					//v1

*p_Indices++ = x + 1 + y * (TERRAIN_X + 1);					//v2

*p_Indices++ = x + 1 + (y + 1) * (TERRAIN_X + 1);				//v4

*p_Indices++ = x + y * (TERRAIN_X + 1);					//v1

*p_Indices++ = x + 1 + (y + 1) * (TERRAIN_X + 1);				//v4

*p_Indices++ = x + (y + 1) * (TERRAIN_X + 1);					//v3

}
}

p_iD3DIndexBuffer9->Unlock();


And this is what I do when I render
	p_iD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255),1.0f,0);

p_iD3DDevice9->BeginScene();
SetupMatrices(); //Setup camera

// Set the location source of our vertex input stream

p_iD3DDevice9->SetStreamSource( 0, p_iD3DVertexBuffer9,0, sizeof(CUSTOMVERTEX));

// Set the default vertex shader to our #defined vertex

//p_iD3DDevice9->SetFVF(CUSTOMVERTEX_FVF);

// Set the location of our index information to our Index Buffer

if(FAILED(p_iD3DDevice9->SetIndices( p_iD3DIndexBuffer9 )))
{
MessageBox(NULL,"Couldn´t set indices", "Error", MB_OK);
return false;
}

//p_iD3DDevice9->DrawPrimitive(D3DPT_POINTLIST,0,128*128);

p_iD3DDevice9->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
0,
256*6*256,
256*6*256,
0,
512*256);

p_iD3DDevice9->EndScene();

RECT rRect;
rRect.left = 0;
rRect.top  = 0;
rRect.right = 480;
rRect.bottom = 480;

//Render only from and to the given rect

p_iD3DDevice9->Present(&rRect,&rRect,NULL,NULL);

Sadly it doesn´t display my primitives at all. When I just use the vertexbuffer it displays them with no probs (using pointlist).

##### Share on other sites
You've created an index buffer that can contain 196608, 16 bit indices. You then locked and loaded the first 16384 indices in the buffer in your loops. Now you're trying to draw 131072 triangles, each of which takes 3 indices. What's wrong with this picture?

Have you upped the debug level via the DX Control Panel applet and looked for debug messages being output to the debugger when you run this app?

Have you tested the return value from DrawIndexedPrimitive when no triangles show up?

How many vertices are in your vertex buffer? According to the parameters you're passing to DrawIndexedPrimitive it would have to, at a minimum, contain 786432 vertices.

What are the values of TERRAIN_X and TERRAIN_Z?

Are you certain that the values you're stuffing into the index buffer will fit in 16 bits? From the MinIndex and NumVertices you're passing to DrawIndexedPrimitive (assuming those are correct), I'd doubt it. Also, you've typed p_Indices as a pointer to short data - it should be unsigned short.

You might want to check MaxVertexIndex and MaxPrimitiveCount in the caps bits to make certain you aren't asking your card to render something it cannot do.

Good luck!