Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
ColonelThirtyTwo edited this page May 31, 2012 · 4 revisions

LuJGL is an assistant library to make using OpenGL with LuaJIT+FFI easier. It uses GLFW for window creation and input, and optionally stb_image (compiled as a shared library) for texture loading.

Usage is fairly simple:

  • require() the library. LuJGL will load OpenGL and others at this point.
  • Call lujgl.initialize(window_title, width, height). Width and height are optional and default to 640x480.
  • Call lujgl.setIdleCallback(func) to set a function to be called to do application logic.
  • Call lujgl.setRenderCallback(func) to set a function to draw the scene.
  • Call lujgl.setEventCallback(func) to set a function to handle window events. The callback function takes at least one argument, which is the event type (string). The rest of the arguments are event-specific values. The event callback may return something depending on the event type.
  • Call lujgl.mainLoop() begin the main loop.
  • Signal the main loop to stop by using the lujgl.signalQuit function.

LuJGL loads the following libraries:

  • lujgl.gl: OpenGL
  • lujgl.glu: GLU
  • lujgl.glfw: GLFW
  • lujgl.stb_image: stb_image (Optional, may not be loaded)
  • lujgl.glext: Not a "library", but a special table with metamethods to automatically load (and cache) extension functions (ex. lujgl.glext.glCompressedTexImage2DARB)

LuJGL also contains some utility functions:

  • lujgl.getTime(): Equivalent to lujgl.glfw.glfwGetTime
  • lujgl.fps(): Returns frames rendered divided by the time passed since this function was last called.
  • lujgl.loadTexture(filepath, fchannels, mipmaps, wrap): Loads an image from disk using stb_image. Not available if stb_image isn't loaded.
  • lujgl.begin2D(): Sets up matrices and settings for 2D rendering in screen-space (for HUDs, etc.)
  • lujgl.end2D(): Ends 2D rendering and restores the settings from when lujgl.begin2D was called.
Clone this wiki locally