Выбрать главу

  glColor3f(0.0,1.0,0.0);

  break;

 case 3:

  glColor3f(0.0,0.0,1.0);

  break;

 }

 glBegin(GL_QUADS);

 glVertex3f(x_small,10.0,z_big); /* front */

 glVertex3f(x_small,0.0,z_big);

 glVertex3f(x_big,0.0,z_big);

 glVertex3f(x_big,10.0,z_big);

 glVertex3f(x_big,10.0,z_small); /* back */

 glVertex3f(x_big,0.0,z_small);

 glVertex3f(x_small,0.0,z_small);

 glVertex3f(x_small,10.0,z_small);

 glVertex3f(x_big,10.0,z_big); /* right */

 glVertex3f(x_big,0.0,z_big);

 glVertex3f(x_big,0.0,z_small);

 glVertex3f(x_big,10.0,z_small);

 glVertex3f(x_small,10.0,z_small); /* left */

 glVertex3f(x_small,0.0,z_small);

 glVertex3f(x_small,0.0,z_big);

 glVertex3f(x_small,10.0,z_big);

 glVertex3f(x_small,10.0,z_big); /* top */

 glVertex3f(x_big,10.0,z_big);

 glVertex3f(x_big,10.0,z_small);

 glVertex3f(x_small,10.0,z_small);

 glVertex3f(x_small,0.0,z_small); /* bottom */

 glVertex3f(x_big,0.0,z_small);

 glVertex3f(x_big,0.0,z_big);

 glVertex3f(x_small,0.0,z_big);

 glEnd();

}

/**********************************************************************/

If you know anything about 3D graphics, you'll probably notice this program is horrendously inefficient. This can easily be changed with OpenGL, but I don't have time to explain how…I leave it as an exercise to the reader (that's what us tutorial people say when we don't feel like doing something :P).

Go ahead and compile this and play around with it…you'll notice there's no collision detection and no way to turn around. This is only the tip of the iceburg as far as OpenGL goes; in fact it's almost embarrassing how much I left out! If you want to find out more about projection, texture mapping, colors, lighting, tesselation, nurbs, fog, stenciling, quadrics, and more, I'd reccomend the following books:

The OpenGL Superbible

The Complete Guide to OpenGL Programming for Windows NT and Windows 95

By Richard S. Wright Jr. and Michael Sweet

Waite Group Press

ISBN 1-57169-073-5

A great book for beginners, which also covers native Win32 graphics with OpenGL… highly reccomended!

The OpenGL Programming Guide, Second Edition

The Official Guide to Learning OpenGL, Version 1.1

By Mason Woo, Jackie Neider and Tom Davis

Addison-Wesley Developers Press

ISBN 0-201-46138-2

Contains *everything* you ever wanted to know about OpenGL 1.1, although it may be a little "thick." Perhaps better used as a reference, but contains invaluable info about the GLUT.

Also check out http://www.opengl.org for the latest OGL info & software.

Lastly, if you ever want to contact me, I'm availible at kased811@ix.netcom.com. I'm afraid I can't offer freelance OpenGL guidance, but if you want to talk about the contemplation of your navel, I'm all ears :P. In the meantime, happy coding and good luck with OpenGL!