Geert Arien

LearnOpenGL examples

The tutorials you can find on learnopengl.com are a great way to learn the basics of 3D rendering and get familiar with the OpenGL API. For simplicity’s sake I decided to implement them in C instead of C++. And instead of using raw opengl I used the Sokol libraries, which makes it a lot easier to support multiple platforms.

Refraction Backpack
A cubemap used as skybox and as an environment map for refraction.

The Sokol libraries are a set of simple STB-style cross-platform libraries written in C. It provides us with all the functionality we need to write GUI applications that run on Windows, Linux, MacOS and WebAssembly. Sokol also supports iOS and Android, but I decided to ignore native builds for mobile platforms. A big motivation to use these libraries is the WebAssembly support, it allows us to compile the examples for the web and provide live demos.

Sokol comes with a simple 3D-API wrapper with support for multiple backends: GLES2/WebGL, GLES3/WebGL2, GL3.3, D3D11 and Metal. The shaders are written in GLSL v450 and cross-compiled to other shader dialects using sokol-shdc. Under the hood sokol-shdc uses glslang, SPIRV-tools and SPIRV-Cross for compiling the shader first from GLSL to SPIR-V and then from SPIR-V to the target shader dialect.

For the live demos I took a lot of inspiration from the sokol samples website. I copied most of the webpage generator and template code from that project, making some small adjustments to style and layout.

This project is still a work in progress and will be updated regularly. In the meantime you can find live demos of all implemented examples at the link below:

Live Demos