JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
Previous Page
Next Page

1.5. State

OpenGL was designed as a state machine for updating the contents of a frame buffer. The process of turning geometric primitives, images, and bitmaps into pixels on the screen is controlled by a fairly large number of state settings. These state settings are orthogonal to one anothersetting one piece of state does not affect the others. Cumulatively, the state settings define the behavior of the OpenGL rendering pipeline and the way in which primitives are transformed into pixels on the display device.

OpenGL state is collected into a data structure called a graphics context. Window-system-specific functions create and delete graphics contexts. Another window-system-specific call designates a graphics context and an OpenGL frame buffer that are used as the targets for subsequent OpenGL commands.

Quite a few server-side state values in OpenGL have just two states: on or off. To turn a mode on, you must pass the appropriate symbolic constant to the OpenGL command glEnable. To turn a mode off, you pass the symbolic constant to glDisable. You enable client-side state (such as pointers that define vertex arrays) with glEnableClientState and disable it with glDisableClientState.

OpenGL maintains a server-side stack for pushing and popping any or all of the defined state values. This stack can be manipulated with glPushAttrib and glPopAttrib. Similarly, client state can be manipulated on a second stack with glPushClientAttrib and glPopClientAttrib.

glGet is a generic function that can query many of the components of a graphics context. Symbolic constants are defined for simple state items (e.g., GL_CURRENT_COLOR and GL_LINE_WIDTH), and these values can be passed as arguments to glGet to retrieve the current value of the indicated component of a graphics context. Variants of glGet return the state value as an integer, float, double, or boolean. More complex state values are returned by "get" functions that are specific to that state value, for instance, glGetClipPlane, glGetLight, and glGetMaterial. Error conditions can be detected with the glGetError function.

Previous Page
Next Page

visit us
JavaScript EditorAjax Editor     JavaScript Editor