Welcome back to OpenGL Fundamentals: Your First Triangle! In our previous lesson, we successfully set up vertex data and uploaded our triangle geometry to the GPU. However, as we mentioned at the end, our window remained blank despite all that careful preparation. That's because we're missing a crucial piece of the puzzle: shaders.
Today, in our third lesson, we'll write our first GPU programs that will finally bring our triangle to life on the screen. Shaders are small programs written in GLSL (OpenGL Shading Language) that run directly on the graphics card, telling it exactly how to process our vertex data and determine the final pixel colors. We'll create two essential shaders: a vertex shader to position our triangle and a fragment shader to color it. By the end of this lesson, we'll have a complete rendering pipeline that transforms our vertex data into visible pixels.
Modern OpenGL operates on a programmable pipeline, which means we have direct control over how the GPU processes our geometry. This is fundamentally different from older fixed-function pipelines, where rendering behavior was predetermined. With programmable shaders, we can customize every step of the rendering process.
The two most essential stages we need to program are the vertex stage and the fragment stage. The vertex shader runs once for each vertex in our triangle, transforming 3D positions and preparing data for the next stages. The fragment shader then runs for each pixel that needs to be colored, determining the final color output. Between these stages, the GPU automatically handles tasks like connecting vertices into triangles and determining which pixels are covered.
Think of shaders as specialized functions: the vertex shader is like a position calculator that decides where each corner of our triangle appears on screen (this gets mapped onto the normalized OpenGL coordinate space!), while the fragment shader is like a paint bucket that decides what color to fill each pixel. Both work together to transform our simple array of numbers into visible geometry.

