【问题标题】:How to pass SDL_Surface to SDL_LockTexture with PySDL2?如何使用 PySDL2 将 SDL_Surface 传递给 SDL_LockTexture?
【发布时间】:2014-02-10 21:09:00
【问题描述】:

我正在尝试将 SDL_Surface 成员传递给 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 在这里定义:surface.py

...
class SDL_Surface(Structure):
_fields_ = [
            ...
            ("pitch", c_int),
            ("pixels", c_void_p),
            ...
...

SDL_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 类型。我做错了什么?

【问题讨论】:

    标签: python sdl-2 pysdl2


    【解决方案1】:

    我遇到了同样的问题,试图将像素传递给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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多