To draw a triangle with OpenGL, you supply geometry, configure the pipeline, and issue a draw call. The pipeline turns points in space into fragments, shades them, and writes the resulting image to a framebuffer. section 7.1.2 section 7.6
A draw call sets the pipeline in motion:
- Vertex processing: A vertex shader runs for each vertex. It can move points or use matrix math to project a 3D scene onto the screen. section 7.1.2
- Rasterization: Vertices are assembled into shapes, which are converted into fragments. section 7.1.2
- Fragment processing: A fragment shader runs on each fragment and determines its color. Fragments are then assembled into an image. section 7.1.2 section 7.4.4
Figure 7.1 The rasterization pipeline
Follow the pipeline from vertex processing through rasterization and fragment processing. section 7.1.2
One triangle
A draw call for one triangle processes three vertices in the vertex shader. The rasterized triangle produces fragments according to the screen space it occupies, and the fragment shader runs on each one. section 7.4.4
Vertex attributes provide the inputs for each vertex, usually including its position. Attribute data lives in buffers; the vertex shader works with one set of attributes at a time, allowing parallel processing. A vertex array object (VAO) preserves attribute state, including layouts and properties, for use with shader programs. section 7.4.4
Listing 7.12 An abstract object
var vao: c_uint = undefined; c.glGenVertexArrays(1, &vao); #1 defer c.glDeleteVertexArrays(1, &vao); #2
Create a VAO name and arrange for its deletion with Zig’s defer. The VAO still needs vertex data to configure. section 7.4.4
