OpenGL Programming Guide

A Drawing Survival Kit (State Management and Drawing Geometric Objects) (OpenGL Programming)

This section explains how to clear the window in preparation for drawing, set the colors of objects that are to be drawn, and force drawing to be completed. None of these subjects has anything to do with geometric objects in a direct way, but any program that draws geometric objects has to deal with these […]

Describing Points, Lines, and Polygons (State Management and Drawing Geometric Objects) (OpenGL Programming) Part 1

This section explains how to describe OpenGL geometric primitives. All geometric primitives are eventually described in terms of their vertices— coordinates that define the points themselves, the endpoints of line segments, or the corners of polygons. The next section discusses how these primitives are displayed and what control you have over their display. What Are […]

Describing Points, Lines, and Polygons (State Management and Drawing Geometric Objects) (OpenGL Programming) Part 2

Restrictions on Using glBegin() and glEnd() The most important information about vertices is their coordinates, which are specified by the glVertex*() command. You can also supply additional vertex-specific data for each vertex—a color, a normal vector, texture coordinates, or any combination of these—using special commands. In addition, a few other commands are valid between a […]

Basic State Management (State Management and Drawing Geometric Objects) (OpenGL Programming)

In the preceding section, you saw an example of a state variable, the current RGBA color, and how it can be associated with a primitive. OpenGL maintains many states and state variables. An object may be rendered with lighting, texturing, hidden surface removal, fog, and other states affecting its appearance. By default, most of these […]

Displaying Points, Lines, and Polygons (State Management and Drawing Geometric Objects) (OpenGL Programming) Part 1

By default, a point is drawn as a single pixel on the screen, a line is drawn solid and 1 pixel wide, and polygons are drawn solidly filled in. The following paragraphs discuss the details of how to change these default display modes. Point Details To control the size of a rendered point, use glPointSize() […]

Displaying Points, Lines, and Polygons (State Management and Drawing Geometric Objects) (OpenGL Programming) Part 2

Polygons as Points, Outlines, or Solids A polygon has two sides—front and back—and might be rendered differently depending on which side is facing the viewer. This allows you to have cutaway views of solid objects in which there is an obvious distinction between the parts that are inside and those that are outside. By default, […]

Normal Vectors (State Management and Drawing Geometric Objects) (OpenGL Programming)

A normal vector (or normal, for short) is a vector that points in a direction that’s perpendicular to a surface. For a flat surface, one perpendicular direction is the same for every point on the surface, but for a general curved surface, the normal direction might be different at each point on the surface. With […]

Vertex Arrays (State Management and Drawing Geometric Objects) (OpenGL Programming) Part 1

You may have noticed that OpenGL requires many function calls to render geometric primitives. Drawing a 20-sided polygon requires at least 22 function calls: one call to glBegin(), one call for each of the vertices, and a final call to glEnd(). In the two previous code examples, additional information (polygon boundary edge flags or surface […]

Vertex Arrays (State Management and Drawing Geometric Objects) (OpenGL Programming) Part 2

Dereferencing a List of Array Elements glArrayElement() is good for randomly "hopping around" your data arrays. Similar routines, glDrawElements(), glMultiDrawElements(), and glDrawRangeElements(), are good for hopping around your data arrays in a more orderly manner. void glDrawElements(GLenum mode, GLsizei count, GLenum type, void * indices); Defines a sequence of geometric primitives using count number of […]

Vertex Arrays in Buffer Objects (State Management and Drawing Geometric Objects) (OpenGL Programming)

Advanced While vertex arrays help reduce the number of function calls to specify geometric objects, the data still resides in the client’s memory. Every time you want to utilize the enabled vertex arrays for rendering, the data is transferred from the client to the OpenGL server. While that may be as simple as sending data […]