views:

258

answers:

1

I'm using a 3rd party DLL to load in some raw image data, and I want to use this raw image data as a texture in openGL. However, the c function returns a void*, and I need to somehow convert this so it will work as the "pixels" parameter to glTexImage2D. Right now my code looks like something this:

data = c_void_p(vdll.vlImageGetData()) 
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB8, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, data )

However, I get a TypeError complaining that data 'cannot be converted to pointer'. Does anyone know how to get this to work?

Edit: Figured it out. Basically what I do is this:

data = create_string_buffer( BUFFER_SIZE )
data = dll.vlImageGetData()
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB8, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, data )
+1  A: 

An answer to a similar question suggested to use ctypes.cast().

wr
This doesn't work because the pyopenGL expects the pixels param to be a raw string. I can't use c_char_p because that expects a null-terminated string. I need a way to convert that void pointer into a raw python string.
aeflash
Have you already seen http://osdir.com/ml/python.ctypes/2004-12/msg00002.html ? If yes and it didn't help, you should provide a small stand-alone skript that we can execute locally.
wr