Essential Drawing with OpenGL ES

In OpenGL, you draw in 3D space. You start out by specifying a series of points, also called vertices. Each of these points will have three values: one for the x coordinate, one for the y coordinate, and one for the z coordinate.

These points are then joined together to form a shape. You can join these points into a variety of shapes called primitive shapes, which include points, lines, and triangles in OpenGL ES. Note that in OpenGL, primitive shapes also include rectangles and polygons. As you work with OpenGL and OpenGL ES, you will continue to see differences whereby the latter has

330 chapter 10 ■ programming 3D GRApHICS With OpENGL

fewer features than the former. Here's another example: OpenGL allows you to specify each point separately, whereas OpenGL ES allows you to specify them only as a series of points in one fell swoop. However, you can often simulate OpenGL ES's missing features through other, more primitive features. For instance, you can draw a rectangle by combining two triangles.

OpenGL ES offers two primary methods to facilitate drawing:

• glVertexPointer

• glDrawElements

Note We'll use the terms "API" and "method" interchangeably when we talk about the OpenGL ES APIs.

You use glVertexPointer to specify a series of points or vertices, and you use glDrawElements to draw them using one of the primitive shapes that we pointed out earlier. We'll describe these methods in more detail, but first let's go over some nomenclature.

The names of these OpenGL and OpenGL ES APIs all begin with gl. Following gl is the method name. The method name is followed by an optional number such as 3, which points to either the number of dimensions—such as (x,y,z)—or the number of arguments. The method name is then followed by a data type such as f for float. (You can refer to any of the OpenGL online resources to learn the various data types and their corresponding letters.)

We'll tell you about one more convention. If a method takes an argument either as a byte (b) or a float (f), then the method will have two names: one ending with b, and one ending with f. Let's now look at each of the two drawing-related methods, starting with glVertexPointer.

0 0

Post a comment