[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaJIT + glXGetProcAddress
- From: Henk Boom <henk@...>
- Date: Thu, 15 Mar 2012 17:23:20 -0400
Hi, I'm writing a pure-ffi binding for the 'new' opengl api, using
glXGetProcAddress and such. I'm running into a problem, though, that
the bound functions don't seem to be working properly. I think it must
be an error I'm making in understanding the ffi semantics, but I've
looked over the documents on luajit.org and don't see anything.
Here's an example of getting at glCreateShader through the ffi
------------------------------------------------
local ffi = require 'ffi'
local libgl = ffi.load('GL')
ffi.cdef[[
typedef unsigned int GLenum;
typedef unsigned char GLubyte;
typedef unsigned int GLuint;
extern void (*glXGetProcAddress(const GLubyte *procname))( void );
typedef GLuint (*PFNGLCREATESHADERPROC) (GLenum type);
]]
local GL_VERTEX_SHADER = 0x8b31
local glCreateShader =
ffi.cast('PFNGLCREATESHADERPROC', libgl.glXGetProcAddress('glCreateShader'))
print(glCreateShader(GL_VERTEX_SHADER))
------------------------------------------------
I would expect glCreateShader to return a non-zero value, as per the
spec, but it returns 0 (opengl's null handle) every time. I should
mention that an opengl context of the proper version has already been
initialized at this point through GLFW. To make sure it was not an
opengl context issue I tried compiling the following c code to a
native lua module:
------------------------------------------------
static int gl__glCreateShader(lua_State *L)
{
PFNGLCREATESHADERPROC glCreateShader =
(PFNGLCREATESHADERPROC)glXGetProcAddress("glCreateShader");
lua_pushnumber(L, glCreateShader(
luaL_checknumber(L, 1)));
return 1;
}
------------------------------------------------
Unless I've misunderstood something, this should be more or less
equivalent. Calling this c function from the same place as the above
ffi code returns 1, which is a valid shader handle. I'm pretty sure
this means that I'm using the ffi improperly, do problems stand out to
anyone?
henk