View on GitHub
Download as .tar.gz
Download as .zip

The OpenGL API is not usually found in a OS as a straight C library, or at least not all of it is. Instead, the OS supplies a loader API (called WGL in Windows, GLX in Linux, CGL in MacOS X) through which you retrieve pointers to actual OpenGL functions. So while the OpenGL functions and constants themselves are standard, you can only get access to a working OpenGL namespace through a platform-specific API.

local gl = require'winapi.gl11'

local gl = require'winapi.gl21'

Get an OpenGL 1.1 or 2.1 namespace. Functions are discovered automatically through WGL and their pointers memoized for later calls.

Below are the function prototypes and constants that are accessible in the gl namespace depending on which OpenGL version you load:

local glu = require'glu'

The GLU API contains auxiliary utilities that let you set a perspective transform or an orthogonal transform or move the camera, among other things. glu_lua implements a few of these for environments that don't have a GLU implementation.

local glut = require'glut'

The GLUT API lets you render the Utah Teapot (other stuff not included).

local wgl = require'winapi'


The WGL API provides wglCreateContext for creating an OpenGL context on a HDC. It also provides wglGetProcAddress for discovery of OpenGL functions.

For a straight application of the WGL API see module winapi.wglpanel.

local wglex = require'winapi'


The WGLEXT API provides various Windows-specific OpenGL extensions.


  • make OpenGL constants C enums and access them through a proxy table into ffi.C.
  • make a binding to regal instead, which should be faster or at least more memory efficient.