Create an unitary cube. It is very easy to create it:
It's vertexes are:
GLfloat vertex[] = { -1.0, -1.0, 1.0, // 0
1.0, -1.0, 1.0, // 1
1.0, 1.0, 1.0, // 2
-1.0, 1.0, 1.0, // 3
-1.0, -1.0, -1.0, // 4
1.0, -1.0, -1.0, // 5
1.0, 1.0, -1.0, // 6
-1.0, 1.0, -1.0}; // 7
Now, create an array of how the faces are connected. Using QUAD as exemple,
GLuint faces[] = { 0, 1, 2, 3,
1, 5, 6, 2,
5, 4, 7, 6,
7, 4, 0, 3,
3, 2, 6, 7,
0, 4, 5, 1 };
Let's say that you create a function, called cube()
, in which you passed this coordinates to the driver.
Now, to have any kind of cube, just specify the scale transformation to transform this unitary cube. For example, to make a cube of 4 units:
scale(4.0, 4.0, 4.0);
cube();
and so on