|How to…||Functions You’ll Use|
|Enable and disable rendering options||glEnable/glDisable|
|Query the state of rendering options||glIsEnabled/glGetInteger/glGetFloat/glGetDouble|
|Save and restore some or all of the current state||glPushAttrib/glPopAttrib|
The rendering state is one of the things that make OpenGL so fast and efficient at drawing 3D graphics. This state is grouped logically into different categories such as color, lighting, texturing, and so forth. Each rendering context (HRC) that you create has its own rendering state specific to a window or off-screen bitmap.
Unlike most of the other chapters, this chapter does not contain any complete example programs. Rather, you will find these state functions used in examples for every other chapter in the book.
OpenGL’s two functions that enable and disable rendering features are called, appropriately enough, glEnable and glDisable. You pass these functions a single enumerated constant, such as GL_DEPTH_TEST, as follows:
glEnable(GL_DEPTH_TEST); /* Enable depth buffer testing */ glDisable(GL_DEPTH_TEST); /* Disable depth buffer testing */
You can retrieve the current state using glIsEnabled, glIsDisabled, and glGetBooleanv, as in the following:
GLboolean state; /* * GL_TRUE if depth testing is enabled… */ state = glIsEnabled(GL_DEPTH_TEST); /* * GL_TRUE if depth testing is disabled… */ state = glIsDisabled(GL_DEPTH_TEST); /* * Returns Boolean state value; GL_TRUE if depth testing is enabled… */ glGetBooleanv(GL_DEPTH_TEST, &state);
Most OpenGL state variables are Boolean values, on or off. Some, like the current viewport, are an array of integers, or an array of floating point numbers for the current RGBA color. To address these types of state values, OpenGL adds glGetDoublev, glGetFloatv, and glGetInteger:
GLint istate; GLfloat fstate; GLdouble dstate; glGetIntegerv(GL_VIEWPORT, istate); glGetFloatv(GL_CURRENT_COLOR, fstate); glGetDoublev(GL_CURRENT_NORMAL, dstate);
You’ll learn more about the various state variables further into the chapter.
|Previous||Table of Contents||Next|