0

Heya, I just wanted some help with using vertex arrays. I wrote a Q3BSP map loader and this is the code that does the rendering, and it works as intended:

glBegin(GL_TRIANGLES);
for (int i = 0; i < curFace.meshVertexCount; i++) {
    int meshIndex = meshvertices[curFace.meshVertexOffset + i].offset;
    glVertex3fv(vertices[curFace.vertexOffset + meshIndex].position);
}
glEnd();

But when I switch to vertex array for speed, the screen shows up blank:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_INDEX_ARRAY);

glVertexPointer(3, GL_FLOAT, sizeof(Vertex), vertices[curFace.vertexOffset].position);
glDrawElements(GL_TRIANGLES, curFace.meshVertexCount, GL_INT, &meshvertices[curFace.meshVertexOffset].offset);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);

Also, here would be the relevant headers:

// 10 - Vertex
struct Vertex {
    float position[3];
    float texCoord[2][2];
    float normal[3];
    unsigned char colour[4];
};

// 11 - MeshVertex
 struct MeshVertex {
    int offset;
};
std::vector<Vertex> vertices;
std::vector<MeshVertex> meshvertices;

I could post the entire code if you'd like, but most of that might be irrelevant.

Edited by LeeZH: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by LeeZH
0

Nevermind. The problem was solved when I switched to GL_UNSIGNED_INT at line 5 for some reason.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.