A draw call tells the graphics system to render geometry using its current configuration. In OpenGL, it starts the rasterization pipeline: vertices are processed, geometry is assembled into shapes, and fragments are shaded and written to a framebuffer. section 7.1.2 section 7.6
OpenGL keeps much of that configuration in a context. A draw call uses the currently bound vertex array object (VAO) for vertex attributes and the currently bound shader program for processing. Bind the program with glUseProgram—not glBindProgram, despite the tempting name. section 7.4.1 section 7.4.6 section 7.4.4
For a simple triangle, glDrawArrays selects triangles and tells OpenGL to process three vertices. Other draw-call functions use different mechanisms. A draw call modifies the framebuffer only where it draws primitives, so clear the screen each frame to avoid leftovers from earlier frames. section 7.4.6 section 7.4.4
Listing 7.15 Drawing with data
while (c.GLFW_FALSE == c.glfwWindowShouldClose(window)) {
c.glClearColor(0.1, 0.2, 0.2, 1.0); #1
c.glClear(c.GL_COLOR_BUFFER_BIT); #2
{
c.glBindVertexArray(vao); #3
defer c.glBindVertexArray(0);
c.glUseProgram(shader_program); #3
defer c.glUseProgram(0);
c.glDrawArrays(c.GL_TRIANGLES, 0, 3); #4
}
c.glfwSwapBuffers(window); #5
c.glfwPollEvents();
}
Follow the frame loop: clear the color buffer, bind the VAO and program, draw three vertices, then swap buffers and poll events. Zig's defer statements unbind the VAO and program when the inner scope ends. section 7.4.6
