Before an application can draw with OpenGL, it needs an OpenGL context. The context stores the state associated with an instance of OpenGL; think of it as the configuration for the rendering pipeline. Change that state through OpenGL functions, then issue a draw call to write pixels to the current framebuffer. section 7.4.1 section 7.6
An OpenGL object holds state of its own. When the object is bound to the context, its state is mapped into the context’s state. Objects can refer to stored data and state such as shaders, images, and geometry. section 7.4.1 section 7.6
GLFW handles platform-specific work and lets an application request OpenGL features and acquire a context. To call OpenGL functions consistently across platforms, glad supplies an OpenGL 3.3 Core header and loads the system’s OpenGL implementation. This avoids relying on operating-system headers that may be missing or out of sync with supported versions. section 7.1.3
Listing 7.7 Aren’t you glad we’re loading GL?
pub fn main() !void {
// ... from init to window ...
const glad_res = c.gladLoadGL(@ptrCast(&c.glfwGetProcAddress)); #1
if (glad_res == 0) return error.GladLoadGlFailed; #1
// ... main loop ...
}
After window setup, this Zig listing loads OpenGL through GLFW’s procedure-address function and checks for failure. section 7.4.1
