Game Development Reference
In-Depth Information
4 OpenGL lighting and
textures
So far we have looked at the mathematics behind the basic geometry of
computer graphics, the way this geometry can be displayed on a
computer screen and using the standard graphics library, OpenGL, to put
some simple geometry on the screen. This chapter is where things start
to look so much more convincing. Animation that uses some kind of
lighting model has a realism that unshaded models can never match.
While realism may not be your goal in terms of the geometry that you are
displaying, your characters may be extreme caricatures, or have a cute
cartoon feel; the overall display will still benefit from the use of a lighting
model. OpenGL allows the developer a huge amount of flexibility in the
way that your characters and scenes are displayed. Much of this flexibility
stems from the intelligent use of the OpenGL lighting model, lights and
materials. In this chapter we will look first at how to set up a simple lighting
model and then how to set the surfaces of your geometry so that it uses
all the features that OpenGL offers. Finally, we will look at the way that
textures can be added to the surface of the geometry that you are
displaying. Along the way, we will introduce some new OpenGL drawing
techniques that help optimize the drawing routines.
Using lights in OpenGL
In order to use lights in OpenGL lighting calculations must be enabled.
This is done in the usual way by using
glEnable(GL_LIGHTING)
In each implementation of OpenGL there are at least eight lights
available. If you are at all familiar with a CGI program then you will find
these lights easy to understand. If you have ever done any studio
photography then you will find the lights highly desirable. OpenGL lights
Search Nedrilad ::




Custom Search