Quote:
void Q3Map::Build(){ PointContainer= new Q3Vertex[numIndex]; for(int index=0; index < numIndex; index++) { PointContainer[index].position[0] = verts[indices[index]].position[0]; PointContainer[index].position[1] = verts[indices[index]].position[1]; PointContainer[index].position[2] = verts[indices[index]].position[2]; }}
This was only for immediate mode because you have to build a container where 3 points make up a triangle, then the next three points make the next triangle and so on...
Triangle1 = (1., 2., 3.);Triangle2 = (2., 3., 4.);Triangle3 = (3., 4., 5.);...Pointcontainer:(1,2,3, 2,3,4, 3,4,5, ...)
This is pretty memory intense because you have to store the same vertices more than once and every vertex is made of 3 components.
Indexed Vertex Arrays avoid this overhead because they use indices (1 int) into an array of unique vertices to build the primitives.
Quake maps are stored in this manner.
I would suggest that you use glDrawelements because glDrawArrays can't render indexed vertex arrays, only the method i told you about in my last post.
... and make additional arrays for vertices, normals, color, .. whatever.
GL can handle interleaved arrays but i find it alot easier and cleaner to have separate arrays (when you have to rebuild them for some reason.)
As AP pointed out you have to use
GL_TRIANGLES because most 3d formats store their primitives as triangles and only some can handle triangle fans ( i don't know any :) )
void Q3Map::Build(){ float *Vertices_fp = new float[3*numVerts]; float *Normals_fp = new float[3*numVerts]; float *TexCoords_fp = new float[4*numVerts]; unsigned char *Color_ucp = new unsigned char[4*numVerts]; for(int VertexIndex=0; VertexIndex<numVerts; VertexIndex++) { Vertices_fp[(3*VertexIndex )] = verts[VertexIndex].position[0]; Vertices_fp[(3*VertexIndex+1)] = verts[VertexIndex].position[1]; Vertices_fp[(3*VertexIndex+2)] = verts[VertexIndex].position[2]; Normals_fp[(3*VertexIndex )] = verts[VertexIndex].normal[0]; Normals_fp[(3*VertexIndex+1)] = verts[VertexIndex].normal[1]; Normals_fp[(3*VertexIndex+2)] = verts[VertexIndex].normal[2]; TexCoords_fp[(4*VertexIndex )] = verts[VertexIndex].texcoord[0][0]; TexCoords_fp[(4*VertexIndex+1)] = verts[VertexIndex].texcoord[0][1]; TexCoords_fp[(4*VertexIndex+2)] = verts[VertexIndex].texcoord[1][0]; TexCoords_fp[(4*VertexIndex+3)] = verts[VertexIndex].texcoord[1][1]; Color_ucp[(4*VertexIndex )] = verts[VertexIndex].color[0]; Color_ucp[(4*VertexIndex+1)] = verts[VertexIndex].color[1]; Color_ucp[(4*VertexIndex+2)] = verts[VertexIndex].color[2]; Color_ucp[(4*VertexIndex+3)] = verts[VertexIndex].color[3];}
Rendering Routine:
void Q3Map::Render(){ glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEX_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(3, GL_FLOAT, 0, Vertices_fp); glNormalPointer(GL_FLOAT, 0, Normals_fp); glTexCoordPointer(2, GL_FLOAT, 0, TexCoords_fp); glColorPointer(4, GL_UNSIGNED_BYTE, 0, Color_ucp); glDrawElements(GL_TRIANGLES, numIndex, GL_UNSIGNED_SHORT, indices); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEX_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);}
I hope the code snippets don't contain many bugs :)
cya
by the way, .. thx for rating :)