Brain Dump

Drawing a Triangle

Tags
opengl guide

After creating an opengl window the first thing to get started on is drawing a triangle. There's a few stages to this so lets work through them in order.

Specify Coordinates

Firstly we need to let OpenGL know what we're trying to draw. We do this by supplying coordinates in normalised device coordinates.

Here are the coordinates for a 2D triangle. Note the z axis is set to \(0\) so it's pointing directly towards you.

float vertices[] = {
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
     0.0f,  0.5f, 0.0f
};