# [SOLVED] Vertex Arrays problem (Quake 3 Map Renderer)

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

## Recommended Posts

Hi all. I am trying to write something like Quake 3 Map Renderer. Untill yesterday, I was rendering world faces "classically" through glVertex between glBegin and glEnd. Yesterday, I have found, this post at this forum (there), where are they talking about using vertex arrays in such a renderer. I have never used vertex arrays, but I have an idea, how it works. Well, but I have been experiencing some problems. I absolutely don't know how to solve it, so I am typing this post... Old renderer (not good, it's rendering quads and so on): Screenshot
    for(int f = 0; f < w.numFaces; ++f) {

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,  w.Lightmaps[w.Faces[f].lightmapID]);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, w.Textures[w.Faces[f].texID]);

if(w.Faces[f].type == 1) {

if(w.Faces[f].numVerts==3) glBegin(GL_TRIANGLES);
else glBegin(GL_POLYGON);

for (int v = 0; v < w.Faces[f].numVerts; ++v) {

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, w.Vertices[w.Faces[f].startVertIndex+v].texCoord[0], w.Vertices[w.Faces[f].startVertIndex+v].texCoord[1]);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, w.Vertices[w.Faces[f].startVertIndex+v].lightmapCoord[0], w.Vertices[w.Faces[f].startVertIndex+v].lightmapCoord[1]);

glColor4ub(w.Vertices[w.Faces[f].startVertIndex+v].color[0], w.Vertices[w.Faces[f].startVertIndex+v].color[1], w.Vertices[w.Faces[f].startVertIndex+v].color[2], w.Vertices[w.Faces[f].startVertIndex+v].color[3]);
glNormal3f(w.Vertices[w.Faces[f].startVertIndex+v].normal[0], w.Vertices[w.Faces[f].startVertIndex+v].normal[1], w.Vertices[w.Faces[f].startVertIndex+v].normal[2]);
glVertex3f(w.Vertices[w.Faces[f].startVertIndex+v].position[0], w.Vertices[w.Faces[f].startVertIndex+v].position[1], w.Vertices[w.Faces[f].startVertIndex+v].position[2]);

}

glEnd();

}

}


New renderer (using vertex arrays and quake3bsp indices (meshverts)): Screenshot
    for(int f = 0; f < w.numFaces; ++f) {

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,  w.Lightmaps[w.Faces[f].lightmapID]);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, w.Textures[w.Faces[f].texID]);

if(w.Faces[f].type == 1) {

glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(sVertex), w.Vertices[w.Faces[f].startVertIndex].color);

glNormalPointer(GL_FLOAT, sizeof(sVertex), w.Vertices[w.Faces[f].startVertIndex].normal);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glTexCoordPointer(2, GL_FLOAT, sizeof(sVertex), w.Vertices[w.Faces[f].startVertIndex].lightmapCoord);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
glTexCoordPointer(2, GL_FLOAT, sizeof(sVertex), w.Vertices[w.Faces[f].startVertIndex].texCoord);

glVertexPointer( 3, GL_FLOAT, sizeof( sVertex ), w.Vertices[w.Faces[f].startVertIndex].position );

glEnable(GL_NORMAL_ARRAY);
glEnable(GL_COLOR_ARRAY);
glEnable(GL_VERTEX_ARRAY);
glDrawElements( GL_TRIANGLES, w.Faces[f].numMeshVerts, GL_UNSIGNED_INT, w.MeshVerts + w.Faces[f].meshVertIndex );

}
}


Just a little note: Engine cannot handle shaders and md3 model rendering, so some things are wrong even on first screenshot. And another one: I think the vertex arrays can be implemented in better way, so I am planning to rewrite it as this problem will be solved. Well, thank you a lot in advance. :) All the best, Bori [Edited by - bori on July 15, 2007 9:37:40 AM]

##### Share on other sites
The results are weird. Can't really help you at that but one thing I spotted was

glEnable(GL_NORMAL_ARRAY);
glEnable(GL_COLOR_ARRAY);
glEnable(GL_VERTEX_ARRAY);

this should really be glEnableClientState(). AFAIK Nvidia hardware also accepts it your way but it is not correct. For vertex array enable disable you have to use glEnable/DisableClientState.

Edit: And you may have to replace the glActiveTexture call to glClientActiveTexture within the if before you set use glTexCoordPointer.
You should really read the OpenGL Specification on those functions to understand why.

##### Share on other sites
Quote:
 Original post by Trenkithis should really be glEnableClientState().

Thank you, I updated it.

But, unhopefully, no change in result (I am using nV 6600).

##### Share on other sites
I Edited my post above. Read it again.

##### Share on other sites
Quote:
 Original post by TrenkiAnd you may have to replace the glActiveTexture call to glClientActiveTexture within the if before you set use glTexCoordPointer.You should really read the OpenGL Specification on those functions to understand why.

That was it! Thank you a lot!

Solved.