Archived

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

xstreme2000

IGRPOWIBCYHMP?

Recommended Posts

I'm Getting Really Pissed Off With Index Buffers Can You Help Me Please? My Q3 BSP loader has come to a stupid stand still because I'm having a problem with my index buffers. I have created my vertex buffer and if I do: lpD3DDevice->DrawPrimitive(D3DPT_POINTLIST, 0, vertex_count); I can see them all on the screen As soon as I put my index buffers in...nothing, so I created an index buffer the same length as my vertex buffer and filled it with values 0 to vertex_count and replaced my DrawPrimitive with lpD3DDevice->SetIndices(lpIB, 0); lpD3DDevice->DrawIndexedPrimitive(D3DPT_POINTLIST, 0, vertex_count, 0, vertex_count); and nothing I know my Index buffer has the right values (I locked it and dumped to a file just before rendering it) and SetIndices doesn't seem to be failing. Any Ideas? I am absolutly sure its something stupid
Render Code: lpD3DDevice->SetStreamSource(0, lpVB, sizeof(bsp_vertex)); lpD3DDevice->SetVertexShader(D3DFVF_BSPVERTEX); // This line will show what I want //lpD3DDevice->DrawPrimitive(D3DPT_POINTLIST, 0, vertex_count); // These two line don't display anything lpD3DDevice->SetIndices(lpIB, 0); lpD3DDevice->DrawIndexedPrimitive(D3DPT_POINTLIST, 0, vertex_count, 0, vertex_count);
Just though I'd post my creation code in case the problem is there
	DWORD sizeofIndices = sizeof(DWORD) * vertex_count;

	// Create the index buffer
	if (FAILED(lpD3DDevice->CreateIndexBuffer(
										sizeofIndices, D3DUSAGE_WRITEONLY,
										D3DFMT_INDEX32,D3DPOOL_DEFAULT, &lpIB)))
	{
		ErrorMessage("CreateIndexBuffer(...) failed!", "CreateIndexBuffer()");		
		return false;
	}

	DWORD *pIndices = NULL;

	// Lock vertex buffer
	if (FAILED(lpIB->Lock(0, 0, (BYTE**)&pIndices, 0))) {
		ErrorMessage("Lock(...) failed!", "CreateIndexBuffer()");
		return false;
	}

	// Copy data into index buffer
	for (int c=0; c<vertex_count; c++)
		pIndices[c] = c;

	// Unlock the index buffer
	lpIB->Unlock();
    
Edited by - xstreme2000 on November 13, 2001 2:59:39 PM Edited by - xstreme2000 on November 13, 2001 3:00:20 PM Edited by - xstreme2000 on November 13, 2001 3:01:42 PM Edited by - xstreme2000 on November 13, 2001 3:17:31 PM Edited by - xstreme2000 on November 13, 2001 3:18:39 PM

Share this post


Link to post
Share on other sites
Here is a section from my own code ... compare it, maybe there is something different in my vertex/index buffer setup


// Initialization and shutdown
BOOL CLandscape::Init (char* sHeightmapFilename, char* sTextureFilename,
char* sDetailTextureFilename)
{
TSingleton sgTextureManager;
TSingleton sg3DGraphics;
TSingleton sgVFS;
CTextureManager* pTextureManager = sgTextureManager.Get();
C3DGraphics* p3DGraphics = sg3DGraphics.Get();
CVFS* pVFS = sgVFS.Get();

VERTEX_LANDSCAPE* v;
WORD* index;

unsigned int iHeightfieldDataLength;
int i, j;

// Grab D3D device
LPDIRECT3DDEVICE8 pD3DDevice = p3DGraphics->GetD3DDevice();

LOG("Landscape...\n");

// Get "base" texture
m_iTexture = pTextureManager->UploadTexture(sTextureFilename);
if (!m_iTexture)
return FALSE;

// Get detail texture
m_iDetailTexture = pTextureManager->UploadTexture(sDetailTextureFilename);
if (!m_iDetailTexture)
return FALSE;

// Try to read heightfield
m_pHeightmap = pVFS->Read(sHeightmapFilename, &iHeightfieldDataLength);
if (!m_pHeightmap)
return FALSE;

// Create and fill vertex buffer
if ( FAILED(pD3DDevice->CreateVertexBuffer( LAND_SIZE * LAND_SIZE * sizeof(VERTEX_LANDSCAPE),
0, D3DFVF_LANDSCAPE,
D3DPOOL_DEFAULT, &m_pVertexBuffer)))
return FALSE;

if (FAILED(m_pVertexBuffer->Lock( 0, 0, (BYTE**)&v, 0 )))
return FALSE;

// Set all vertices in the heightmap so we can draw
// it in one DrawIndexedPrimitive
for (j = 0; j < LAND_SIZE; j++)
{
for (i = 0; i < LAND_SIZE; i++)
{
v->pos.x = (float(i) - 32.0f) * 16.0f;
v->pos.y = float(m_pHeightmap[j*LAND_SIZE+i]) * 2.0f;
v->pos.z = (float(j) - 32.0f) * 16.0f;

v->tu0 = float(i) / 64.0f; // Land texture
v->tv0 = float(j) / 64.0f;

v->tu1 = float(i) / 2.0f; // Detail texture
v->tv1 = float(j) / 2.0f;

v++;
}
}

m_pVertexBuffer->Unlock();

// Create and fill index buffer
if( FAILED( pD3DDevice->CreateIndexBuffer(
(LAND_SIZE-1) * (LAND_SIZE-1)* 6 * sizeof(WORD),
D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
D3DPOOL_DEFAULT, &m_pIndexBuffer ) ) )
return FALSE;

if (FAILED(m_pIndexBuffer->Lock(0, 0, (BYTE**)&index, 0 )))
return FALSE;

// Set up the proper vertex ordering
for (j = 0; j < LAND_SIZE - 1; j++)
{
for (i = 0; i < LAND_SIZE - 1; i++)
{
*index++ = j * LAND_SIZE + i + 1;
*index++ = j * LAND_SIZE + i;
*index++ = (j + 1) * LAND_SIZE + i;

*index++ = (j + 1) * LAND_SIZE + i;
*index++ = (j + 1) * LAND_SIZE + i + 1;
*index++ = j * LAND_SIZE + i + 1;
}
}

m_pIndexBuffer->Unlock();

LOG("Landscape done.\n");

return TRUE;
}

Share this post


Link to post
Share on other sites
I had the same problem with D3DFMT_INDEX32. Use 16 bit indices instead D3DFMT_INDEX16, and change your DWORDs to WORDs. Geforce 2 only supports 16 bit anayways. You can check your card''s support the the caps viewer that comes with the sdk, or query if yourself.

Share this post


Link to post
Share on other sites