Moving into the third dimension

2D games are a thing of the past. They were the only possible option in times when the processing power of the computers or game consoles was not enough to support real 3D drawing and calculations. Modern systems on the other hand are so powerful that even the not optimized programs perform well. So far we have done some basic OpenGL programming focusing on 2D drawing. Isn't it a good time to step into 3D game programming? It is a new world full of challenges.

In the previous samples we were locking the viewer at a standard position and fixed the view point at the beginning of the axes. This was done with the next code.

glViewport (0, 0, (GLsizei)(width), (GLsizei)(height));				// reset the current viewport
glMatrixMode (GL_PROJECTION);							// select the projection matrix
glLoadIdentity ();								// reset the projection matrix
gluPerspective (45.0f, (float)(width)/(float)(height), 1.0f, 1000.0f); 		// calculate the aspect ratio of the window
glMatrixMode (GL_MODELVIEW);							// select the modelview matrix
glClearColor (0.0f, .0f, 0.0f, 1.f);						// black background
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);				// clear screen and depth buffer
glLoadIdentity();								// reset the current modelview matrix<
glTranslatef(0,0,-80);								// move the drawing surface apart

Where am I? What am I looking at?

In order to understand the way OpenGL handles drawing we must talk about some basic things first. Most if not all of the books about OpenGL have a very good but rather technical description of what is going on when you draw in three dimensions. I do not want to add this article to this long list. I would rather like to give you some simple guidelines to help start creating 3D environments in your games and applications. For in depth description you can refer to the book 'OpenGL SuperBible' which is for me the basic source of reference.

The OpenGL approach is very simple. You can imagine it like the stage of a theatre. The system draws only what is on the stage and ignores everything else. Then is the viewer position, which determines the perspective.