[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [LuaJIT FFI feature request] ffi.load name transformation callback
- From: Adam Strzelecki <ono@...>
- Date: Fri, 20 Jan 2012 15:48:05 +0100
FYI this is solution I've used for OpenGL following your advise:
-- index metamethod removing gl prefix for funtions
-- and GL_ prefix for constants
setmetatable(M, { __index = function(t, n)
local s
-- all functions contain at least one small letter
if n:find('[a-z]') then
s = g['gl'..n]
elseif n:find('^UT?_') then
s = g['GL'..n]
else
s = g['GL_'..n]
end
rawset(t, n, s)
return s
end })
And here's sample code that works for me:
-- draw lights positions
gl.UseProgram(0)
gl.Disable(gl.LIGHTING)
gl.Disable(gl.TEXTURE_2D)
gl.PointSize(20)
gl.PushMatrix()
gl.Rotate(lightsRotation, unpack(lightsRotationAxis))
gl.Begin(gl.POINTS)
for l = 1, #lights do
if lights[l].diffuse then gl.Color4f(unpack(lights[l].diffuse)) end
if lights[l].position then gl.Vertex4f(unpack(lights[l].position)) end
end
gl.End()
gl.PopMatrix()
gl.Enable(gl.TEXTURE_2D)
gl.Enable(gl.LIGHTING)
gl.UseProgram(program)
Cheers,
--
Adam Strzelecki