OpenGL Object Support

A C Module for OpenGL support via the OpenGL Object is provided with the XLua distribution. Using the included LuaGL library, OpenGL can be used directly from your Lua code. The OpenGL object is another 3rd party extension, written by Looki.

Usage

Package Name: ext.opengl

The OpenGL module is ext/opengl.dll. By either using the Open External C Module action and using MMF's include external files feature, or by adding the DLL to MMF's Binary Data list, the DLL file can be embedded directly into your built application.

Once included, standard opengl functions will be placed in gl.*, utility library functions will be placed in glu.*, and OpenGL Object-specific functions will be placed in ext.opengl.*.

LuaGL

The LuaGL library includes a full complement of GL functions that mirror the OpenGL API. You don't need to do anything more than bind an OpenGL object to begin using LuaGL in your code. Use the following links for more information:

Differences with LuaGL

The most important difference between the official LuaGL distribution, and the one for XLua, is in handling of OpenGL constants (enumerations). In the standard C API, these are constants like GL_QUADS that are associated with an equivilent integer value.

LuaGL converted all GL constants to strings, sl GL_QUADS would instead be passed as the string "QUADS". XLua goes back to using the original numeric values of the GL constants, which are all stored in named variables in the gl table. So instead of passing "QUADS" to a function like described in the LuaGL documentation, you would pass gl.QUADS.

All supported GL constants are named by taking the original constant name and stripping off the leading GL_. If the constant's name starts with a number however, it still contains a leading underscore, e.g. gl._2D.

This change allows you to add any missing OpenGL constants without requiring a new version of LuaGL for XLua. It's also faster.

Example

-- Require the module, which should be stored in /ext/opengl.dll
-- relative to the application.
require "ext.opengl"

-- The following variable represents the ID that we exported an
-- OpenGL object as.
OBJID = 1

-- Draws a single white pixel in the center of the OpenGL
-- object's canvas.  This function needs to be called each frame.
function draw ()
  ext.opengl.MakeCurrent(OBJID)
  gl.Translate(0,0,-3)
  gl.Begin(gl.POINTS)
  gl.Vertex(0,0,0)
  gl.End()
end

draw()

OpenGL Object

The OpenGL object can be downloaded from its development topic on the Clickteam forums HERE. For any questions, comments, or problems with the OpenGL object, you should contact Looki.

Function Reference

These functions deal with the OpenGL object directly. Each function requires the exported object id of the OpenGL object as its first parameter.

LuaGL supports most of the OpenGL 1.1 specification. The XLua inclusion of LuaGL has expanded this to cover most of the OpenGL specification through 2.0. This reference lists every GL function currently supported.

Take note, many of the parameter lists differ from their GL counterparts, to better reflect usage or limitations inside Lua. Follow the ref link by each function to view full SDK documentation for that function.