Since LÖVE is implemented on top of a GL context opened by the SDL library, you can use OpenGL commands and functions directly in a LÖVE program and draw to the LÖVE window. To get access to the OpenGL API, you need to require some library that allows it, because LÖVE doesn't let you do it. LuaGL is one such library.
This very simple example program draws a Gouraud shaded multicolor triangle on the screen. Its structure should be familiar to everyone who knows a little bit of (the old-style) OpenGL.
Code: Select all
require 'luagl'
function love.update() love.timer.sleep(10) end
function love.draw()
gl.Begin(gl.TRIANGLES)
gl.Color(255, 0, 0)
gl.Vertex(20, 20)
gl.Color(0, 255, 0)
gl.Vertex(400, 120)
gl.Color(0, 0, 255)
gl.Vertex(20, 220)
gl.End()
end
I downloaded a compiled package for Linux. Inside the archive are shared object files that contain the Lua modules. I put the luagl.so file into a directory that is in LUA_PATH and after that the require command just worked.
There are some caveats to doing this:
The code you write like this IS NOT PORTABLE as a LÖVE game, because it requires an external library that must be appropriate for each computer the game is to be run on. You will have hard time distributing your game!
The way LÖVE creates the OpenGL context is not appropriate for all kinds of things you can do with OpenGL proper. You might have to live without some functionality. The coordinate system is not suitable for 3D perspective projections (LÖVE is 2D) and there probably is no depth buffer, so you will have hard time drawing 3D shapes.
Combining OpenGL calls and traditional LÖVE drawing is, ahem, complicated. You might have the stuff you draw not appear when you do this. I'll see if I can work out the rules and see whether making your own love.run helps with this.
Perhaps a future version of LÖVE can support creating different kinds of GL contexts via conf.lua, so we can sneak in some happy 3D stuff with an external library (even though it is naughty)? You know, I might just write up a proposal for this for the issue tracker real soon now. We'll see what comes out of it.
Still, it might be fun to play around with this. Please share your tips for getting LuaGL to work on other OSes. I'll close with a tiny screenshot of the triangle the program draws.