This page contains Red Book (8th edition) OpenGL 4.x example code that I have ported to SDL2 using glm and glew.
I’ve also moved any auxiliary source files and data files to each example folder so that every example can be compiled independently from frameworks/etc.
The original source can be found here.

The reason for doing this, is to make them easily compile on any system with support for SDL2/GLEW/GLM (Currently I have only tested on 64bit Linux with Nvidia 340.24 drivers)

I don’t really have the skills to write an OpenGL 4 tutorial, so if you need guidance beyond the source and the comments, I strongly recommend buying the Red Book (8th edition).

There are simple build scripts for Linux but the source should compile on any system with SDL2, glew(1.10) and glm(
In Linux you only need to install SDL2, glew and glm development packages using your favourite package manager.

An important note when using glew with OpenGL 4.4 / 4.3 is to set

    glewExperimental = GL_TRUE; 

Before calling


OpenGL 4.3 draw commands using SDL2 glew and glm

The original source had a bug when model_matrix was set:

    glUniformMatrix4fv(render_model_matrix_loc, 4, GL_FALSE, model_matrix);

As you can see “count” is set to 4.
This properly happened because some of the other examples had a model_matrix[4] array in the vertex shader, but in this example it must be set to 1

OpenGL 4.3 object instancing (Red Book Chapter 3)

OpenGL 4.3 Shadow mapping (Red Book Chapter 4)

I had to change

    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, depth_texture, 0);


    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_texture, 0);



Not sure why this happens. (Driver is NVIDIA 340.24 on Ubuntu 14.04)

OpenGL 4.3 Cube mapping (Red Book Chapter 6)

I had to use a different 3d object because the object loader used by the Red Book segfaults (on my system) with the object originally used in this example.
Instead of trying to bugfix and change the loader code I just used another object (still from the redbook files).

OpenGL 4.3 Light Models (Red Book Chapter 8)

OpenGL 4.3 Fur shading using geometry shader (RedBook Chapter 10)

I have added error checking in the shader compile since this example didn’t render properly on my GTX675MX at first.
I then found that there was a hardware limit on how many vertices the geometry shader could emit and changed that number.
If the programs exits with an error about Geometry you will have to change the value of max_vertices in “static const char fur_gs_source[]”.

Tessellated Teapot (Red Book Chapter 9)

(This example uses freeglut instead of SDL2)

Order Independent Transparency (Red Book Chapter 11)