Schabby's Blog
Reserve Orbital Defence Commander

In this tutorial, we will discuss how to load a shader in OpenGL.

In order to get up and running with OpenGL and LWJGL, one need to understand the most basic setup of LWJGL. This is important to understand because all following examples will be based on that.

Aug
08.

In the previous article, we discussed the camera transformation which maps a vertex from world space into the camera space. Recall that the camera spans a orthonormal coordinate system with the three vectors $\vec{u}$, $\vec{v}$ and $\vec{w}$, where $-\vec{w}$ points along the viewing direction.

In this section we will deal with the projection of the 3D vertex in camera space into a 2D view plane. In OpenGL, what follows is clipping and mapping to so-called normalized device coordinates which are tightly coupled into the construction of projection matrix. In fact, the pure mathematical construction of the projection matrix is easy. What makes it difficult is the clipping part.

This post provides a clean, up-to-date and concise example on how to set up a simple custom shader in OpenGL that runs out of the box. My target language is Java with LWJGL, but the code can easily be ported to different languages on this level. To my surprise, I is quite difficult to find a state of the art example of a simple yet complete setup for shaders that can serve as a get-go for more complex programs. Most OpenGL shader tutorials are written for the pre-2.0 era (ie. using shaders through ARB extensions) that is long over. This post is therefore trying to provide a modern "Hello World of Shaders" set up example.

In the following post I provide a simple-as-possible math primer to understand basic concepts necessary for 3D graphics. I do not put much emphasize on a formal notation, but rather on understandability and applicability for our case. That is why we always assume the Cartesian Coordinate System and specialize our definitions for three dimensions.