chapter seven

7 Shader Heck

 

This chapter covers

  • The nuanced relationship between hardware accelerated graphics and operating systems
  • Creating a cross-platform application with GLFW
  • OpenGL’s rasterization pipeline: why it exists, what it’s for, and how to use it
  • The basic terminology and ideas behind graphics math, for programmers
  • Zig patterns that make interacting with OpenGL safer and easier

The sun’s rays stream in through the window, crawling towards you. You feel their warmth on your lap. Are they golden because it’s sunset, or because it’s a memory? It’s a nice feeling, until the light starts to overwhelm the poorly backlit monitor that has kept you entranced for the last few hours. You stand in a huff of annoyance and pull the blinds closed. Much better. After all, how are you going to finish this level if you can’t even see the screen?

If you’re anything like me, moments like this were the beginning of a fascination with computing that brought you on a journey you could not have predicted. My obsession with virtual worlds and curiosity for the magic underpinning them morphed into a reverance for real technology and a desire to do build real things. I don’t view virtual worlds as magical anymore. Instead, I see the product of thousands of hours of ingenuity and passion from real people. Perhaps that’s even more incredible.

7.1 Designed by aliens, for aliens

7.1.1 Unfortunately, the history of graphics APIs matters

7.1.2 The rasterization pipeline

7.1.3 Actually getting access to the pipeline

7.2 A minimally messy build process

7.2.1 GLFW

7.2.2 glad

7.3 The canvas

7.3.1 Creating a window with GLFW

7.3.2 Don’t we care about error handling?

7.4 Painting with pixels

7.4.1 Important things with frighteningly vague names

7.4.2 Going to space

7.4.3 There is no shader build system

7.4.4 An object for managing objects

7.4.5 Vexing vertices

7.4.6 The payoff

7.5 Next steps

7.6 Summary