OpenGL primitives
In the simplest terms, primitives are just basic shapes that are drawn in OpenGL. In this section, we will provide a brief overview of the main geometric primitives that are supported by OpenGL and focus specifically on three commonly used primitives (which will also appear in our demo applications): points, lines, and triangles.
Drawing points
We begin with a simple, yet very useful, building block for many visualization problems: a point primitive. A point can be in the form of ordered pairs in 2D, or it can be visualized in the 3D space.
Getting ready
To simplify the workflow and improve the readability of the code, we first define a structure called Vertex
, which encapsulates the fundamental elements such as the position and color of a vertex.
typedef struct { GLfloat x, y, z; //position GLfloat r, g, b, a; //color and alpha channels } Vertex;
Now, we can treat every object and shape in terms of a set of vertices (with a specific color) in space. In this chapter, as...