简体   繁体   中英

Using ctypes.c_void_p as an input to glTexImage2D?

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 )

一个类似问题答案建议使用ctypes.cast()

This may or may not help. There is a similar issue on use of c_void_p as a return type. I instead have to return c_longlong AND do some hokey tricks:

if I am returning a pointer c_types obejct, I have to cast its reference to a POINTER to c_longlong to get the integer value to return. (NOTE that CFUNCTYPE will not accept POINTER(x) types as a return type):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM