Jump to content
  • Advertisement


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


glDrawElements with my Face type crashes

This topic is 5489 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
      delete [] vert;

      delete [] normal;

      delete [] texcoord;

      delete [] lightmapcoord;

      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

    glBindTexture(GL_TEXTURE_2D, *faces[i]->textureID);

    //set the lightmaps up

    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

    glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), &faces[i]->texcoord);
    //assign lightmap pass to point

    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[i]->indices[x] was all right and they both look fine. If its still fuzzy you can look at my complete source here. Can someone please help me? Thanks Nuke [edited by - nukem on October 8, 2003 12:15:49 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!