Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.
ColonelThirtyTwo edited this page Oct 15, 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:

  • 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 Functions
  • lujgl.glconst: OpenGL Constants
  • lujgl.glu: GLU
  • lujgl.glfw: GLFW
  • lujgl.stb_image: stb_image (nil if not loaded)
  • lujgl.glext: Not a "library", but a special table with metamethods to automatically load (and cache) extension functions (ex. lujgl.glext.glCompressedTexImage2DARB)

Utilities:

  • 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.

Events

  • close: Called when the window is closing. Return true to cancel the close action.
  • key: Key event. Takes parameters:
    • down: Boolean down state
    • key: Either a character long string with the key value or a number containing the key code
  • mouse: Mouse click event. Takes parameters:
    • button: Mouse button
    • down: Boolean down state
    • x, y: Mouse coordinates
  • motion: Mouse move event. Takes parameters:
    • x, y: New mouse coordinates
Clone this wiki locally