   Surface structure
  Hi all.I'm trying to implement a engine in C++ using OpenGL.Everything is going well but I got the the part where I need to use actual meshes and I'm not very sure of a fast way to draw a surface on screen and how to store the data.Could someone help me with this?I have like 100 books on game programming each of them tells me different stuff but most don't even go near that subject.I have a class CMesh and I'd like to have a list of surfaces in it. I'd like to store vertex positions, texture coordinates and vertex normals.   
  You'll want to look into vertex arrays and/or VBOs. Typically you would store arrays of vertices, texture coordinates and normals in your mesh class, or possibly an array of 'vertex' structs, each of which contains a position, texture coordinate(s), and a normal. You'll most likely also need an index array.There's a myriad of other details to consider, depending on various factors such as whether your mesh class supports multiple materials (i.e. render states), if/how you want to support batching, etc. But the simplest implementation would probably just store the data in arrays, and then upload and render via glDrawElements().Also, whenever I see class names like 'CMesh', I have to ask: what does the 'C' stand for?   ;  I'm trying right now to do it and it won't work. I get a crash at the glDrawElements command;Let me point you to some code. I've never done this thing with the array pointers before so excuse me if I do anything stupid.Here is my data for a surface:int vert_count;int vert_text_count;int vert_norm_count;int tris_count;float* vert_coords;float* vert_tex_coords;float* vert_norm;UINT* tris;Then the creation method is like this:void CSurface::CreateCube(){this->vert_coords = new float[3*4*6];this->vert_tex_coords = new float[2*4*6];for(int i=0;i<2*4*6;i++)vert_tex_coords = 0; this->vert_norm = new float[3*4*6];for(int i=0;i<3*4*6;i++)vert_norm = 0; this->tris = new UINT[12];this->tris_count = 12;this->vert_count = 4*6;SetVertexPos(1,-1.0,-1.0,-1.0);SetVertexPos(2,-1.0, 1.0,-1.0);SetVertexPos(3, 1.0, 1.0,-1.0);SetVertexPos(4, 1.0,-1.0,-1.0);SetVertexPos(5,-1.0,-1.0, 1.0);SetVertexPos(6,-1.0, 1.0, 1.0);SetVertexPos(7, 1.0, 1.0, 1.0);SetVertexPos(8, 1.0,-1.0, 1.0);SetVertexPos(9,-1.0,-1.0, 1.0);SetVertexPos(10,-1.0, 1.0, 1.0);SetVertexPos(11, 1.0, 1.0, 1.0);SetVertexPos(12, 1.0,-1.0, 1.0);SetVertexPos(13,-1.0,-1.0,-1.0);SetVertexPos(14,-1.0, 1.0,-1.0);SetVertexPos(15, 1.0, 1.0,-1.0);SetVertexPos(16, 1.0,-1.0,-1.0);SetVertexPos(17,-1.0,-1.0, 1.0);SetVertexPos(18,-1.0, 1.0, 1.0);SetVertexPos(19, 1.0, 1.0, 1.0);SetVertexPos(20, 1.0,-1.0, 1.0);SetVertexPos(21,-1.0,-1.0,-1.0);SetVertexPos(22,-1.0, 1.0,-1.0);SetVertexPos(23, 1.0, 1.0,-1.0);SetVertexPos(24, 1.0,-1.0,-1.0);SetTriangle(1,0,1,2);SetTriangle(2,0,2,3);SetTriangle(3,6,5,4);SetTriangle(4,7,6,4);SetTriangle(5,6+8,5+8,1+8);SetTriangle(6,2+8,6+8,1+8);SetTriangle(7,0+8,4+8,7+8);SetTriangle(8,0+8,7+8,3+8);SetTriangle(9,6+16,2+16,3+16);SetTriangle(10,7+16,6+16,3+16);SetTriangle(11,0+16,1+16,5+16);SetTriangle(12,0+16,5+16,4+16);}void CSurface::SetTriangle(int ind,int v1, int v2, int v3){ind = ind-1;tris[ind] = v1;tris[ind+1] = v2;tris[ind+2] = v3;}void CSurface::SetVertexPos(int ind,float x,float y,float z){ind = ind-1;vert_coords[ind*3]=x;vert_coords[ind*3+1]=y;vert_coords[ind*3+2]=z;}void CSurface::SetVertexTexCoords(int ind, float u, float v){vert_tex_coords[ind*2]=u;vert_tex_coords[ind*2+1]=v;}and here is the actuall drawing code:glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer(3,GL_FLOAT,0,this->vert_coords);glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexCoordPointer(2,GL_FLOAT,0,this->vert_tex_coords);glEnableClientState(GL_NORMAL_ARRAY);glNormalPointer(GL_FLOAT,0,this->vert_norm);//glDrawArrays(GL_TRIANGLES,0,(int)this->tris);glDrawElements(GL_TRIANGLES,this->tris_count*3,GL_UNSIGNED_INT,this->tris);;  for fastest geometry output may use:0) Use VBO. on heavy surfaces its may 1) 16 bits indices (on several videocards 32 bits working ~30% slower)2) optimize indices for post TnL cash (use NVTRiStrip for example)its my realisation of surface class in my engine:http://code.google.com/p/sigelengine/source/browse/trunk/surface.cppmay be its not beautiful architecture, but working very fast (faster other engine, Irrlicht, Blitz3D, OGRE, etc)MakeVBO on 857 lineDraw on 1281 line   