It was suggested to me that I have one central rendering engine for all my other engines. I started to convert my engines to use my new rendering engine starting with my Q3BSP(based off the tutorials over at gametutorials) engine. For some reason now that I have converted the Q3BSPFace to my face type(VertexBuffer) the program crashes everytime glDrawElements is called.
Here is my face type VertexBuffer
struct VertexBuffer
{
~VertexBuffer()
{
if(vert)
{
delete [] vert;
}
if(normal)
{
delete [] normal;
}
if(texcoord)
{
delete [] texcoord;
}
if(lightmapcoord)
{
delete [] lightmapcoord;
}
if(indices)
{
delete [] indices;
}
}
Vect3* vert; //holds all the verts
Vect3* normal; //holds all the normals
Vect2* texcoord; //tolds the texture coords
Vect2* lightmapcoord; //holds the lightmap coords
int count; //the number of items in the top 4 arrays
BYTE colors[4]; //hold the color of the face(RGBA)
UINT* textureID; //the texture ID for the face
UINT* lightmapID; //the lightmap ID for the face
int type; //the type of face it is
int shaderindex; //the index for the shader
int* indices; //pointer to an array of indices
int meshvertcount; //the number of mesh verts
};
Here is the code I use to convert BSPFace to my face type, VertexBuffer
//alloc the memory
facecount = lfacecount;
faces = new VertexBuffer[facecount];
//go threw each face
for(int i=0;i<facecount;i++)
{
//put all the indices of each BSPFace into VertexBuffer
faces[i].meshvertcount = lfaces[i].meshvertcount;
faces[i].indices = new int[lfaces[i].meshvertcount];
int k = 0;
for(int j=lfaces[i].meshvertindex;j<(lfaces[i].meshvertindex+lfaces[i].meshvertcount-1);j++,k++)
{
faces[i].indices[k] = indexarray[j];
}
//copy the lightmap and texture IDs over
faces[i].textureID = &texture[lfaces[i].textureID];
faces[i].lightmapID = &lightmaps[lfaces[i].lightmapID];
//the the size of our coords
faces[i].count = lfaces[i].vertcount;
//alloc the memory for all our coords
faces[i].lightmapcoord = new Vect2[faces[i].count];
faces[i].normal = new Vect3[faces[i].count];
faces[i].texcoord = new Vect2[faces[i].count];
faces[i].vert = new Vect3[faces[i].count];
k = 0;
//copy the values over
for(int j=lfaces[i].startvertindex;j<(lfaces[i].startvertindex+lfaces[i].vertcount)-1;j++,k++)
{
faces[i].lightmapcoord[k] = verts[j].lightmapcoord;
faces[i].normal[k] = verts[j].normal;
faces[i].texcoord[k] = verts[j].textcoord;
faces[i].vert[k] = verts[j].pos;
}
}
Here is my rendering function
//render the faces
void CRender::Render()
{
//go threw all the faces and render them
for(int i=0;i<facecount;i++)
{
//set the texture
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *faces[i]->textureID);
//set the lightmaps up
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, *faces[i]->lightmapID);
//set the vertex pointer for each face
glVertexPointer(3, GL_FLOAT, sizeof(VertexBuffer), &faces[i]->vert);
//assign texture pass to point to normal texture coords
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), &faces[i]->texcoord);
//assign lightmap pass to point
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), &faces[i]->lightmapcoord);
//draw it
//it crashes here
glDrawElements(GL_TRIANGLES, faces[i]->meshvertcount, GL_UNSIGNED_INT, faces[i]->indices);
}
}
Ive checked to make sure that faces
->meshvertcount and faces->indices[x] was all right and they both look fine.
If its still fuzzy you can look at my complete source <a href = "http://zonkbonk.virtualave.net/NuclearGraphics.zip">here.</a>
Can someone please help me?
Thanks
Nuke
<SPAN CLASS=editedby>[edited by - nukem on October 8, 2003 12:15:49 AM]</SPAN> </i>
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind