如何使用PySDL2将SDL_Surface传递到SDL_LockTexture?

2024-10-03 11:17:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将SDL_表面成员传递给SDL_LockTexture:

texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height)
surface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000)
SDL_LockTexture(texture, 0, ctypes.byref(surface.contents.pixels), ctypes.byref(surface.contents.pitch))

TypeError: byref() argument must be a ctypes instance, not 'int'

这里定义了SDL曲面:surface.py

^{pr2}$

这里定义了SDL\u LockTexture:render.py

SDL_LockTexture = _bind("SDL_LockTexture", [POINTER(SDL_Texture), POINTER(SDL_Rect), POINTER(c_void_p), POINTER(c_int)], c_int)

在调用SDL_CreateRGBSurface之后,调试器说曲面的像素和间距成员都是int类型的。我做错什么了?在


Tags: 定义contents成员ctypeswidthsurfaceintsdl
1条回答
网友
1楼 · 发布于 2024-10-03 11:17:21

我也遇到了同样的问题,试图将像素传递到PyOpenGL函数中。由于某些原因,字段存储为int。您需要将其转换为void pointer。尝试:

SDL_LockTexture(texture, 0, ctypes.byref(ctypes.c_void_p(surface.contents.pixels)), ctypes.byref(ctypes.c_int(surface.contents.pitch))

相关问题 更多 >