🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problems with Indexed Vertex Buffers

Started by
5 comments, last by jaymz 24 years, 8 months ago
I dunno why, but the first for loop isn't copying correctly.. should read:

for (WORD index=0;index<numvertices;index++)

Advertisement
Try playing with your perspective projection, set it with a really small zmin, and a large zmax. Perhaps some triangles are getting clipped to the near clip plane.

It may be a problem with lighting (they're drawing but they're black) so set the background color to grey, and see if the sillouhettes appear.

Also try disabling culling (D3DRENDERSTATE_CULLMODE = D3DCULL_NONE).

Thanks for the suggestions, tried them all, same result: only 2 faces of the cube are drawn... the one directly facing the viewer and the one directly facing away from the viewer... (of course rotating the object changes the direction, but still those are the only 2 faces drawn)
Make sure you draw your vertices counter-clockwise.. if not, the face will not be visible. I've had the same problem and found the solution in the DirectX SDK docs.
Just noticed something, you're passing object.numpolygons to the DrawIndexedPrimitiveVB() call, shouldn't that be object.numpolygons*3? A cube has 12 triangles for each of its six faces, so instead of passing number of indices required, 36, you pass 12, which would work out to be only two faces of the cube.
Basically, Im loading vertex and polygon data from a file, which all seems to be working fine... but when I make a call to DrawPrimitiveIndexedVB, only 2 of the faces show up.. I've written code to output the vertex list and polygon list out to another file.. they output perfectly, so I don't think the problem is in my loader. I've included the code to load from the file below.. if anyone can see anything I'm overlooking or misunderstanding, please let me know.

int C3dObject::LoadObject(char *filename,CDodgeD3D dodged3d)
{

//temp vars
float tx,ty,tz,vx,vy,vz; //verts and vert normals
WORD ux,uy,uz;
D3DVERTEXBUFFERDESC vbdesc;

FILE *fp_filetemp; // working file

// try and open file
if ((fp_filetemp =fopen(filename,"r"))==NULL)
{
DF_Log("FAILED","LoadObject","Couldn't open the passed file");
return 0;
}

// load in the number of verticies
fscanf(fp_filetemp,"%d",&numvertices);

//load in the number of faces
fscanf(fp_filetemp,"%d",&numpolygons);

//now read all the vertices into the vertex list

//fill in ddsd

ZeroMemory(&vbdesc, sizeof(D3DVERTEXBUFFERDESC));
vbdesc.dwSize= sizeof(D3DVERTEXBUFFERDESC);
vbdesc.dwCaps = D3DVBCAPS_SYSTEMMEMORY; //was 0L .. may need to change back or D3DVBCAPS_SYSTEMMEMORY
vbdesc.dwFVF = D3DFVF_VERTEX;
vbdesc.dwNumVertices = numvertices;

// If this isn't a hardware device, make sure the
// vertex buffer uses system memory.
//if(!driverinfo.hardware)
// vbdesc.dwCaps |= D3DVBCAPS_SYSTEMMEMORY;

// Create a clipping-capable vertex buffer.
if(FAILED(dodged3d.lpd3d->CreateVertexBuffer(&vbdesc,&vertexbuffer, 0)))
{
DF_Log("FAILED","LoadObject","Couldn't create a vertex buffer");
return 0;
}


if( SUCCEEDED(vertexbuffer->Lock(DDLOCK_WAIT,(VOID**)&vertexlist,NULL)))
{
for (WORD index=0;index {
fscanf(fp_filetemp,"%f%f%f%f%f%f",&tx,&ty,&tz,&vx,&vy,&vz);
//vertexlist[index]=D3DVERTEX( D3DVECTOR(tx,ty,tz), D3DVECTOR(vx,vy,vz),0, 0 );
vertexlist[index].x=tx;
vertexlist[index].y=ty;
vertexlist[index].z=tz;
vertexlist[index].nx=vx;
vertexlist[index].ny=vy;
vertexlist[index].nz=vz;

}

vertexbuffer->Unlock();
}

// now read in all faces
numindices=numpolygons*3;
polygonlist=(WORD*)malloc(sizeof(WORD)*numindices);

for (int index2=0; index2 {
fscanf(fp_filetemp, "%d%d%d",&ux,&uy,&uz);
polygonlist[index2]=ux;
polygonlist[index2+1]=uy;
polygonlist[index2+2]=uz;

} //end for index2

// close the file
fclose(fp_filetemp);

// return success
return 1;
}

and then in Begin Scene I call the following:

cdodged3d.lpd3ddevice->DrawIndexedPrimitiveVB( D3DPT_TRIANGLELIST, object.vertexbuffer,0,object.numvertices,
object.polygonlist,object.numpolygons,D3DDP_WAIT);

[This message has been edited by jaymz (edited October 17, 1999).]

OMG I am sooo stupid.. thanks alot.. numpolys was exactly the problem... I should be shot for such a stupid overlook.. I messed with that code for 4 days....

This topic is closed to new replies.

Advertisement