MoonGL is a Lua binding library for OpenGL.
It runs on GNU/Linux, MacOS, and on Windows (MSYS2/MinGW) and requires Lua (>=5.3), OpenGL (>=3.3), and GLEW.
Authored by: Stefano Trettel
MIT/X11 license (same as Lua). See LICENSE.
See the Reference Manual.
Setup the build environment as described here, then:
$ git clone https://github.com/stetre/moongl
$ cd moongl
moongl$ make
moongl$ make install # or 'sudo make install' (Ubuntu and MacOS)
Below is an "Hello, World!" example, using MoonGLFW as windowing library.
Other examples can be found in the examples/ directory contained in the release package.
-- Script: hello.lua
gl = require("moongl")
glfw = require("moonglfw")
glfw.window_hint('context version major', 3)
glfw.window_hint('context version minor', 3)
glfw.window_hint('opengl profile', 'core')
window = glfw.create_window(600, 400, "Hello, World!")
glfw.make_context_current(window)
gl.init() -- this is actually glewInit()
function reshape(_, w, h)
print("window reshaped to "..w.."x"..h)
gl.viewport(0, 0, w, h)
end
glfw.set_window_size_callback(window, reshape)
while not glfw.window_should_close(window) do
glfw.poll_events()
-- ... rendering code goes here ...
gl.clear_color(1.0, 0.5, 0.2, 1.0) -- GLFW orange
gl.clear("color", "depth")
glfw.swap_buffers(window)
end
The script can be executed at the shell prompt with the standard Lua interpreter:
$ lua hello.lua