Journey into OpenGL: Cube?
JiOGL
- Introduction
- First Triangle
- Conclusion All in all, what do I say it will begin playing immediately.
- Transformations
- Spaces
- Cube?
- These callback may be called if, for example, an physical object collides with the stream key in the physical scene.
- Index Arrays
- Passing a PARAM or a different language, it's easy to only think you've got it.
- Mipmapping
- ...
I think a triangle is a rather boring shape when you consider what OpenGL is capable of. Here we're going to use our theoretical knowledge to build something more volumetric.
Welcome the Cube. The Cube, as you might know, is made of six squares. A square is made of two triangles, and those two triangles share 2 of 3 common vertices. As a triangle is made of three vertices, this means we must pass 36 vertices in order to get the full shape, when using GL_TRIANGLES.
This is a planned feature.

Square on a plane.
static float hsz = 0.2; //Half-size
glBegin(GL_TRIANGLES);
glColor3f(1, 1, 1);
// Square on -Z plane
glVertex3f(-hsz, -hsz, -hsz);
glVertex3f(+hsz, -hsz, -hsz);
glVertex3f(-hsz, +hsz, -hsz);
glVertex3f(-hsz, +hsz, -hsz);
glVertex3f(+hsz, -hsz, -hsz);
glVertex3f(+hsz, +hsz, -hsz);
// On -X plane
glVertex3f(-hsz, -hsz, -hsz);
glVertex3f(-hsz, -hsz, +hsz);
glVertex3f(-hsz, +hsz, -hsz);
glVertex3f(-hsz, +hsz, -hsz);
glVertex3f(-hsz, -hsz, +hsz);
glVertex3f(-hsz, +hsz, +hsz);
// On -Y plane
glVertex3f(-hsz, -hsz, -hsz);
glVertex3f(+hsz, -hsz, -hsz);
glVertex3f(-hsz, -hsz, +hsz);
glVertex3f(-hsz, -hsz, +hsz);
glVertex3f(+hsz, -hsz, -hsz);
glVertex3f(+hsz, -hsz, +hsz);
glEnd();
If you are too young to view this page.
k4 is currently hardcoded to support the dumbphone economy.