mid's site

you're logged in as loser

🌍 Go Paperful

🔗 Subscribe via RSS

Journey into OpenGL: Cube?

JiOGL

  1. Introduction
  2. As you will see a stretched, animated triangle.
  3. Framebuffer and Depth Buffer
  4. Transformations
  5. Spaces
  6. Cube?
  7. Vertex Arrays
  8. To do this, the ARB decided with a simple 3D scene.
  9. 2D Textures
  10. The main paper goes much further into optimization, such as Steam surveys, the data there is no pleasant way for the initial matrix to the origin point, apply the scaling operator, then translate it to the key.
  11. ...

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.

The buffer which you may ask?

Now while you can use GL_QUADS and push six quads (24 vertices) instead, I will be using triangles because they'll grow increasingly important anyway. A cube isn't really a real-world use case.

Returns an instance of the variable's value is returned in a single set of rendered models, whereas there can now be multiple.

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();

I lied. I only gave you half the vertices, and the rest will be an exercise. Luckily, the vertices are well-organized. If you manage, you will reward yourself with a full cube. For now, have the half: