Proper OpenGL dynamic library

  • From: Dimiter 'malkia' Stanev <malkia@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 11 Jul 2012 20:57:10 -0700

    Hi folks,

This post is not directly connected with LuaJIT, but if you are using any of the OpenGL FFI bindings you might be interrested.

One little problem with OpenGL ffi bindings (not limited to luajit only) is getting around missing OpenGL extensions, like glCreateShader on Windows. Although it's possible to get and call each extension by luajit/ffi alone, it's a bit nuisance to have to do it in first place. And wrapping "C" exported functions and "lua" wrappers under one dll "table" (gl.Xxxx) might create some slowdowns (I've tried it long time ago, and it was not pretty).

The C/C++ folks had it the easy way with GLEW/GLEE/GL3W and others, but these are C/C++ pre-processor macro tricksters that are not straight forward to port to luajit/ffi land. So instead of going through all hurdles, there is a solution (and multi-platform at that):

    http://github.com/p3/regal

On Windows it would create regal32.dll that exports every glXxx function, wglXxx and two RegalXxx ones. Instead of loading OPENGL32.DLL, load REGAL32.DLL in it's place (gl = ffi.load("regal32")).

There is also iOS, Android, OSX and GLX (Linux) support, but not sure what it achieves there. The library can be compiled with optional logging, asserts/error checking so it might be useful for other stuff too.

I hope I haven't disturbed the forum by posting something a bit irrelevant, but thought it's somewhat related and might ease the pain for people using OpenGL through the wondrous FFI.

    Thanks,
    Dimiter 'malkia' Stanev.

P.S. The default regal.sln for VS2010 targets MSVCR100.dll (/MD), you can retarget static linking /MT - this way you don't have to distribute VS2010 dll's around. It's a bit big dll - 3mb (32-bit version), but switching from /O2 to /O1 and optimizing for size could make it down to 2mb.

Other related posts: