for (WORD index=0;index<numvertices;index++)
🎉 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
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).
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).]