liveBook · Manning

Chapter 7: The baroque world of computer graphics

What you will learn in chapter 7 of Systems Programming with Zig

The chapter introduces hardware-accelerated graphics as a visible form of systems programming and explains why working with GPUs is demanding.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces hardware-accelerated graphics as a visible form of systems programming and explains why working with GPUs is demanding.

Key terms: GPUs, hardware accelerated graphics, graphics APIs, resources with connected lifetimes, invisible computing

7.1 Designed by aliens, for aliens

The section explains why OpenGL provides a common interface across competing graphics hardware and distinguishes graphics from window and input management.

Key terms: OpenGL, standard interface, device drivers, graphics, windows, input, hardware acceleration, GPUs

7.1.1 Unfortunately, the history of graphics APIs matters

The section explains why OpenGL can feel awkward yet remains worth learning, why the chapter uses OpenGL 3.3 Core, and where readers can look for further help.

Key terms: OpenGL, boilerplate, build integration, Raylib, Unity, Unreal Engine, OpenGL 3.3 Core, Vulkan, hardware, official reference material

7.1.2 The rasterization pipeline

This section maps how OpenGL turns vertex data into an image through the rasterization pipeline.

Key terms: OpenGL, Raylib, rasterization, rasterization pipeline, vertices, draw call, vertex shader, rasterizer, fragments, fragment shader

7.1.3 Actually getting access to the pipeline

This section explains why reaching an OpenGL draw call requires platform-specific implementations, desktop-environment support, and libraries that bridge those differences.

Key terms: OpenGL, specification, driver implementation, platform agnostic, desktop environment, GUI window, user input, GLFW, OpenGL context, OpenGL features

7.2 A minimally messy build process

This section introduces a Zig graphics project’s dependency-management challenge and a basic build-and-run workflow.

Key terms: dependency management, GLFW, glad, build.zig, bindings, src/, main.zig, zig build run, edit-compile-run cycle, run steps

7.2.1 Translating GLFW

This section explains linking GLFW and translating its C headers into a Zig-importable module.

Key terms: static linking, dynamic linking, system libraries, C translation, root source file, header files, glfw3 system library, module, translate-c, helper struct

7.2.2 glad

This section generates a project-specific glad library, vendors its source, and integrates it into the Zig build.

Key terms: glad, OpenGL 3.3, core profile, compatibility profile, extensions, vendoring, vendor code, src/c.h, GLFW, translate-c

7.3 The canvas

7.3.1 Creating a window with GLFW

This section introduces the GLFW window application pattern, C-style error checks, and double buffering for displaying complete frames.

Key terms: GLFW, loop, frame, GLFW_TRUE, GLFW_FALSE, NULL, error sets, framebuffer, double buffered, front buffer

7.3.2 Don’t we care about error handling?

This section explains how to inspect and report GLFW errors from Zig and configure the requested OpenGL version before window creation.

Key terms: glfwGetError, error code, out parameter, error callback, error inspection, callconv(.c), C ABI, calling convention, [*c]const u8, [*:0]const u8

7.4 Painting with pixels

7.4.1 Important things with frighteningly vague names

This section introduces OpenGL contexts and objects as stateful, opaque abstractions used to configure the pipeline and manage its data.

Key terms: context, state, pipeline, draw call, framebuffer, object, binding, object name, integer identifier, GLFW

7.4.2 Going to space

This section explains the coordinate systems, vertex representation, and winding order used to define a triangle for OpenGL.

Key terms: coordinate system, screen space, normalized device coordinates, vertex shader, clip space, w, clipped, winding order, counter-clockwise, back-facing

7.4.3 There is no shader build system

This section defines simple GLSL shaders as Zig strings and manually compiles and links them into an OpenGL program.

Key terms: shader object, program object, compile, link, glad, multiline string, global constants, @embedFile, GLSL, vertex shader

7.4.4 An object for managing objects

This section connects vertex and fragment processing to vertex attributes and introduces vertex array objects for preserving attribute state.

Key terms: vertex shader, geometry, rasterized, fragment shader, fragments, draw calls, vertex attributes, buffers, position, vertex array object

7.4.5 Vexing vertices

This section explains how to store triangle vertices in a VBO and configure a VAO to supply them to a vertex shader.

Key terms: vertex buffer object, VBO, VAO, vertex shader, vertex attributes, object name binding, targets, GL_ARRAY_BUFFER, defer, glBufferData

7.4.6 The payoff

This section draws a triangle by invoking the rasterization pipeline with bound OpenGL objects and clearing the framebuffer each frame.

Key terms: VAO, program object, glUseProgram, glDrawArrays, rasterization pipeline, primitives, framebuffer, draw calls, clear the screen

7.5 Next steps

The section suggests two tools for exploring graphics programs and GLSL shaders beyond the chapter’s triangle example.

Key terms: RenderDoc, Shadertoy, GLSL, vertex attributes

7.6 Summary

Concepts explained in this chapter

← Chapter 6: A CHIP-8 interpreter

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.