bit101 / glsteps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GL Steps

This repo is just a set of example OpenGL applications done in go-gl as I learn my way around the technology.

There are a few useful resources that I've been working with:

But even with those as guides, there are SO many steps involved just with drawing a single triangle to the screen. Very difficult to know where to start. So I started breaking it down to the absolutely bare-bones minimum, making sure I understood that, and adding as little else as I could add for each step, aiming for a single unit of understanding in each one.

Although not written expressly as a tutorial, I think it can be used pretty well as a way to learn go-gl step by step.

Here's where I'm at so far:

  • Step 1 This is the absolute minimum amount of code I could make and still have an OpenGL window appear on the screen and not crash.
    • Initialize glfw
    • Create a window
    • Loop until the window is killed
  • Step 2 I add a bit more safety code here.
    • Lock the OS thread before doing anything, as is best practice in go-gl
    • Terminate glfw when the app is done
  • Step 3 Orginazation and window stuff.
    • Move a few of the steps into their own functions
    • Add quite a bit more to the code that creates the window
  • Step 4 Input processing.
    • Defer the glfw termination (minor change)
    • Input processing closes the window when the user hits the escape key
  • Step 5 Now I start to add some actual gl calls:
    • Initialize OpenGL
    • Set the viewport
    • Set a clear color, clear the screen and swap buffers to make the change take effect
    • Shows a red canvas
  • Step 6 Draws a triangle! Whole lot of changes here that couldn't really be broken down any further.
    • Create a vertex shader and fragment shader sources as string constants
    • Create shaders from the shader sources and create a program from the shaders
    • Create vertices as a list of float32s
    • Create a vertex buffer object and vertex array object from the vertices
    • Use the program, bind the vertex array and draw the vertices using the shader program
    • Shows a yellow triangle on the red canvas
  • Step 7 Loads the shaders and vertices from external files
    • Shaders are defined in two external text files
    • Vertices are defined in an external json file
    • Constants hold the paths to these files
    • Files are loaded and processed appropriately
    • Still draws a yellow triangle on a red canvas
  • Step 8 The vertex shader now defines the fragment color
    • Vertex shader creates an out vec4 and assigns a velue to it
    • Fragment shader reads this value and uses it
  • Step 9 Uniforms
    • The fragment shader sets a uniform vec4 to read its color from
    • The main program looks for the location of the uniform variable
    • It sets the value of that uniform
  • Step 10 Animated color
    • The main program calculates an ever-changing set of r, g, b values based on time
    • It passes those rgb values to the uniform read by the fragment shader
  • Step 11 Some clean up and best practices
    • Lock os thread in init
    • Delete shaders after making program
    • Show gl version
  • Step 12 Per-vertex colors
    • Vertex data file contains color values next to position values
    • Main app sets up vertex attribs to read position data seperately from color data
    • Vertex shader updated to read position and color values and pass vertex color to fragment shader
    • Fragment shader updated to read vertex color from vertex shader

About


Languages

Language:Go 99.9%Language:Makefile 0.1%