Archived

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

RageMatrix

Rendering a Cube with TRIANGLESTRIP....

Recommended Posts

Hey all, I''m messing with D3D8 at the mo and have been creating a cube class. Currently, the cube is set up like so...
  
void CCube::Create(LPDIRECT3DDEVICE8 _pD3DDevice, D3DVECTOR *v1, D3DVECTOR *v2, D3DVECTOR *v3, D3DVECTOR *v4, D3DVECTOR *v5, D3DVECTOR *v6, D3DVECTOR *v7, D3DVECTOR *v8)
{
	pD3DDevice = _pD3DDevice;
	// Setup the vertex buffer

	pD3DDevice->CreateVertexBuffer(sizeof(CTexturedVertex)*24, NULL, D3DFVF_CTexturedVertex, D3DPOOL_MANAGED, &pTexturedVertexBuffer);
	// Lock the vertex buffer.

	pTexturedVertexBuffer->Lock(0, 0, (BYTE **)&vtxCube, NULL);

	// Set up cube vertices.

	// FRONT

	vtxCube[0].Create(v1->x,  v1->y, v1->z, 1, 1, 1, 0, 1);
	vtxCube[1].Create(v2->x,  v2->y, v2->z, 1, 1, 1, 0, 0);
	vtxCube[2].Create(v3->x,  v3->y, v3->z, 1, 1, 1, 1, 1);
	vtxCube[3].Create(v4->x,  v4->y, v4->z, 1, 1, 1, 1, 0);
	// RIGHT

	vtxCube[4].Create(v4->x,  v4->y, v4->z, 1, 1, 1, 0, 0);
	vtxCube[5].Create(v5->x,  v5->y, v5->z, 1, 1, 1, 1, 0);
	vtxCube[6].Create(v3->x,  v3->y, v3->z, 1, 1, 1, 0, 1);
	vtxCube[7].Create(v6->x,  v6->y, v6->z, 1, 1, 1, 1, 1);
	// BACK

	vtxCube[8].Create(v6->x,  v6->y, v6->z, 1, 1, 1, 0, 1);
	vtxCube[9].Create(v5->x,  v5->y, v5->z, 1, 1, 1, 0, 0);
	vtxCube[10].Create(v7->x, v7->y, v7->z, 1, 1, 1, 1, 1);
	vtxCube[11].Create(v8->x, v8->y, v8->z, 1, 1, 1, 1, 0);
	// LEFT

	vtxCube[12].Create(v8->x, v8->y, v8->z, 1, 1, 1, 0, 0);
	vtxCube[13].Create(v2->x, v2->y, v2->z, 1, 1, 1, 1, 0);
	vtxCube[14].Create(v7->x, v7->y, v7->z, 1, 1, 1, 0, 1);
	vtxCube[15].Create(v1->x, v1->y, v1->z, 1, 1, 1, 1, 1);
	// BOTTOM

	vtxCube[16].Create(v1->x, v1->y, v1->z, 1, 1, 1, 0, 1);
	vtxCube[17].Create(v3->x, v3->y, v3->z, 1, 1, 1, 1, 1);
	vtxCube[18].Create(v7->x, v7->y, v7->z, 1, 1, 1, 0, 0);
	vtxCube[19].Create(v6->x, v6->y, v6->z, 1, 1, 1, 1, 0);
	// TOP

	vtxCube[20].Create(v2->x, v2->y, v2->z, 1, 1, 1, 0, 1);
	vtxCube[21].Create(v8->x, v8->y, v8->z, 1, 1, 1, 0, 0);
	vtxCube[22].Create(v4->x, v4->y, v4->z, 1, 1, 1, 1, 1);
	vtxCube[23].Create(v5->x, v5->y, v5->z, 1, 1, 1, 1, 0);

	// Unlock the vertex buffer.

	pTexturedVertexBuffer->Unlock();

	// Set up the Render state for texture.

	// Setp to merge colours between vertex colour and texture colour.

	pD3DDevice->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_MODULATE);
	pD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
	pD3DDevice->SetTextureStageState(0,D3DTSS_COLORARG2, D3DTA_DIFFUSE);
	// Turn off the alpha channel since texture doesn''t have one.

	pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP, D3DTOP_DISABLE);
}
  
All looked well, until I added a function to make the cube translucent, at which point I noticed a rogue triangle within the cube running from the front top left vertex to the bottom back vertices. It is only visible from "behind" the cube, on account of backface culling. How do I get rid of this and just render a hollow cube? I read somewhere on here that using triangle strips may be the problem. Do I need to use a triangle list instead? If I do stick with the triangle strip, have I got too many vertices? Thanks for any help. Rage_Matrix Tron Software -=Kicking Butt and Writing Code=-

Share this post


Link to post
Share on other sites