Array Help

Hey I Was Wondering If Anyone Could Help Me Understand Arrays, Basically I Want To Create A Grid Using The Following Code:

glBindTexture(GL_TEXTURE_2D, texture[35]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0,0.0,0.0);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0,0.0,5.0);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0,5.0,5.0);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0,5.0,0.0);
glEnd();

Which Will Draw 1 Square And Texture It, Is There Anyway To Store All This Info In 1 Section Of An Array, E.g. If I Had An Array Called Grid[6][6], Could I Store The Info Above In Grid[0][0], Then The Next Square In Grid[0][1] And So On To Make It Easily Accessible?

Or Can An Array Only Hold Numbers And Not Whole Strings Of Code?

Thanks

Well, I know you said arrays, but one way to do this is to store each texture binding plus quad in its own display list. For instance, see this link:

Just make sure you put the glBindTexture just before the glBegin inside the glNewList/glEndList block, as is mentioned in this thread. Then your Grid[6][6] is an array of GLuint, where each is a display list handle. The advantage of using a display list is you can store not only the whole geometry batch (vertex data such as texcoords, vertex positions, etc. plus the batch type of QUADS) but you can also store the texture bind in it. When you want to draw a face, you just glCallList( Grid[#][#] ). Simple!

Or Can An Array Only Hold Numbers And Not Whole Strings Of Code?

If by “Array” you mean “vertex array” in the GL sense, then essentially yes. A vertex array can just hold all the vertex positions (glVertex data items), or all the vertex texcoords (all the glTexCoord data items), etc. If you use vertex arrays, you still have to issue separate calls to OpenGL to tell it to “draw some QUADS with these vertex arrays” and to “bind the texture” beforehand (i.e. glBindTexture).

For bunches of polygons, vertex arrays are gonna be a lot faster than glTexCoord…glVertex…glTexCoord…glVertex… (which GL folks call “immediate mode”). But if you’ve just got a few polys to draw, it doesn’t make a hill of beans difference. Note also that there are other draw methods that can be even faster than plain vertex arrays (such as VBOs and display lists) if you really need lots of performance. But I wouldn’t start out sweating that. Start with immediate mode as you are. It’s easy to understand. And use display lists for convenience.

I always found this page http://www.songho.ca/opengl/gl_vertexarray.html and this page http://www.songho.ca/opengl/gl_vbo.html very handy when I wanted to double check my understanding on arrays.