A GUI window is a bounded on-screen region for displaying and interacting with application content. For OpenGL, it is the canvas you need before you can draw. A desktop environment provides the window and generally coordinates user input as well. section 7.3 section 7.1.3
On Linux, a display server such as X11 or Wayland coordinates input and output between clients, including GUI windows. Platform expectations vary, so an OpenGL specification alone does not provide a portable window. section 7.1.3
Listing 7.3 Ready, set, loop!
pub fn main() !void {
const init_success = c.glfwInit(); #1
if (init_success == c.GLFW_FALSE) return error.GlfwInitFailed; #1
defer c.glfwTerminate(); #2
const window = c.glfwCreateWindow(1280, 720,
"learning opengl", null, null); #3
if (window == null) return error.GlfwCreateWindowFailed; #3
defer c.glfwDestroyWindow(window);
c.glfwMakeContextCurrent(window); #4
while (c.glfwWindowShouldClose(window) == c.GLFW_FALSE) { #5
// ... handle input and draw stuff ...
c.glfwSwapBuffers(window); #6
c.glfwPollEvents(); #7
}
}
This Zig loop initializes GLFW, creates a 1280-by-720 window, makes its context current, and runs until the window should close. It checks initialization and creation failures and defers cleanup. section 7.3.1
The loop swaps buffers and polls events each frame. GLFW windows are double-buffered by default: drawing goes to a hidden back framebuffer, then swapping makes the completed frame visible instead of exposing an incomplete picture. section 7.3.1
Listing 6.11 All your window
const c = @cImport({ #1
@cInclude("raylib.h"); #2
});
pub fn main() !void {
c.InitWindow(640, 480, "All your window are belong to us!"); #3
defer c.CloseWindow(); #4
c.SetTargetFPS(60); #5
while (!c.WindowShouldClose()) { #6
c.BeginDrawing(); #7
defer c.EndDrawing(); #7
c.ClearBackground(c.BLACK); #8
}
}
Raylib takes a framework-shaped approach: import its C header, create a window, set a target frame rate, and redraw inside its application loop. This example clears a 640-by-480 window to black. section 6.4.2
