Using so-called vertex arrays is probably the most reliable way to optimize such a scene. Here is a good tutorial:
http://www.songho.ca/opengl/gl_vertexarray.html
A vertex array or, more generally, a gl data array stores data, such as vertex positions, normals, colors. You can also have an array containing indexes for these buffers to indicate in which order to draw them.
Then you have several closely related functions that manage these arrays, distribute them, set data for them, and draw them. You can render a complex grid with just one OpenGL command, for example glDrawElements()
These arrays are usually found in host memory. Another optimization is the use of vertex buffer objects, which are the same concept as regular arrays, but are located in the GPU memory and can be somewhat faster. Here is abit about it:
http://www.songho.ca/opengl/gl_vbo.html
Working with buffers unlike the good old glBegin() .. glEnd() has the advantage of being compatible with OpenGL ES. in OpenGL ES, arrays and buffers are the only way to draw stuff.
--- EDIT
Moving things, turning them and transforming them into a scene is performed using the View Model matrix and does not require any changes to the grid data. To illustrate:
you have initialization:
void initGL() { // create set of arrays to draw a player // set data in them // create set of arrays for ball // set data in them } void drawScene { glMatrixMode(GL_MODEL_VIEW); glLoadIdentity(); // set up view transformation gluLookAt(...); drawPlayingField(); glPushMatrix(); glTranslate( player 1 position ); drawPlayer(); glPopMatrix(); glPushMatrix(); glTranslate( player 2 position ); drawPlayer(); glPopMatrix(); glPushMatix(); glTranslate( ball position ); glRotate( ball rotation ); drawBall(); glPopMatrix(); }
source share