Manipulating geometry
In Chapter 4, Organizing a Virtual Filesystem, we created the Bitmap
class to load and store bitmaps in an API-independent way. Now we will create a similar abstraction for geometry data representation that we will later use to submit vertices and their attributes to OpenGL.
Getting ready
Before we proceed with the abstraction, let's take a look at how the vertex specification in OpenGL works. Submitting vertex data to OpenGL requires you to create different vertex streams, and specify ways of their interpretation. Refer to the tutorial if you are unfamiliar with this concept at http://www.opengl.org/wiki/Vertex_Specification.
How to do it…
We have to decide which vertex attributes, or vertex streams, we will store in our mesh. Let's assume that for a given vertex we need a position, texture coordinates, a normal, and a color.
The following are the names and indices of these streams:
const int L_VS_VERTEX = 0; const int L_VS_TEXCOORD = 1; const int L_VS_NORMAL = 2; const...