Using ctypes.c_void_p as input to glTexImage2D?

I am using a third party DLL to load some raw image data and I want to use that raw image data as a texture in openGL. However, function c returns void * and I need to convert it somehow to make it work as a "pixels" parameter for glTexImage2D. My code now looks something like 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 am getting a TypeError complaining that the data "cannot be converted to a pointer". Does anyone know how to get this to work?

Edit: Figured it out. Basically what I am doing:

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 source to share


2 answers


And he suggested using the answer to a similar questionctypes.cast()

.



+1


a source


This may or may not help. A similar problem has to do with using c_void_p as the return type. Instead, I have to return c_longlong and do some hockey tricks:

If I return a pointer to c_types obejct, I have to specify its POINTER reference for c_longlong to get the returned integer value. (NOTE: CFUNCTYPE will not accept POINTER (x) types as return type):



retvalp = cast (byref (retval), POINTER (c_longlong)) #retval is what I want to return return retvalp.contents.value

0


a source







All Articles