Indexed primitive won't render

Started by
0 comments, last by DaJudge 19 years, 8 months ago
What is wrong with this:

	ftVertex	vtest[8];
	vtest[0] = ftVertex(-1.0f, 1.0f, -1.0f, D3DCOLOR_COLORVALUE(1.0, 0.0, 0.0, 1.0));
	vtest[1] = ftVertex(1.0f, 1.0f, -1.0f, D3DCOLOR_COLORVALUE(0.0, 1.0, 0.0, 1.0));
	vtest[2] = ftVertex(-1.0f, -1.0f, -1.0f, D3DCOLOR_COLORVALUE(0.0, 0.0, 1.0, 1.0));
	vtest[3] = ftVertex(1.0f, -1.0f, -1.0f, D3DCOLOR_COLORVALUE(1.0, 1.0, 0.0, 1.0));
	vtest[4] = ftVertex(-1.0f, 1.0f, 1.0f, D3DCOLOR_COLORVALUE(1.0, 0.0, 1.0, 1.0));
	vtest[5] = ftVertex(-1.0f, -1.0f, 1.0f, D3DCOLOR_COLORVALUE(0.0, 1.0, 1.0, 1.0));
	vtest[6] = ftVertex(1.0f, 1.0f, 1.0f, D3DCOLOR_COLORVALUE(1.0, 1.0, 1.0, 1.0));
	vtest[7] = ftVertex(1.0f, -1.0f, 1.0f, D3DCOLOR_COLORVALUE(1.0, 0.0, 0.0, 1.0));

	unsigned short	itest[] = {
		0, 1, 2, 3,
		4, 5, 6, 7,
		4, 6, 0, 1,
		5, 2, 7, 3,
		1, 6, 3, 7,
		0, 2, 4, 5
	};

	vertexCount = 8;
	faceCount = 24;

	void *pTmp;

	if(FAILED(pDevice->CreateVertexBuffer(8 * sizeof(ftVertex), D3DUSAGE_WRITEONLY, VERTEX_FVF, D3DPOOL_MANAGED, &pVB)))
		return;
	if(FAILED(pVB->Lock(0, sizeof(pTmp), (BYTE**)&pTmp, 0)))
		return;
	memcpy(pTmp, vtest, 8 * sizeof(ftVertex));
	pVB->Unlock();

	if(FAILED(pDevice->CreateIndexBuffer(24 * sizeof(unsigned short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &pIB)))
		return;
	if(FAILED(pIB->Lock(0, sizeof(pTmp), (BYTE**)&pTmp, 0)))
		return;
	memcpy(pTmp, itest, 24 * sizeof(unsigned short));
	pIB->Unlock();

	// Render...

	pDevice->SetStreamSource(0, pVB, 0);
	pDevice->SetVertexShader(VERTEX_FVF);
	pDevice->SetIndices(pIB, 0);
	pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, vertexCount, 0, faceCount / 3);


I just want to render the triangles with my vertex and index buffers. The problem is that nothing is rendered, or at least it looks like nothing is rendered. Btw, i'm using directx 8, as I am planning on porting the code to the X-box.
Advertisement
If this is the first thing you want to render with that program, you might try to do following things to get ANYTHING on screen:

disable culling
disable z-buffering
check your view / projection matrix
setup a simple texture stage configuration (like D3DTA_DIFFSE & D3DTOP_SELECTARGx)

Once that works you can start doing more complex stuff. At least that's the way I start my engines.

And if you want to port to XBOX - do yourself a favor and start the port right now. Although the differences are rather subtle there ARE differences - and finding those in a fully blown engine might end up being a really huge pain.

Cheers,
Alex
Alexander Stockinger
Programmer

This topic is closed to new replies.

Advertisement