我想知道使用SDL_GetWindowSize()
的适当方法是什么。根据我得到的错误信息,我不应该使用WIDTH和HEIGHT,因为它们是整数。那么应该在他们的地方使用什么?
import sdl2
APP_SHORT_NAME = 'Test'
WIDTH = 400
HEIGHT = 400
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
window = sdl2.SDL_CreateWindow(
APP_SHORT_NAME.encode('ascii'),
sdl2.SDL_WINDOWPOS_UNDEFINED, sdl2.SDL_WINDOWPOS_UNDEFINED,
WIDTH, HEIGHT, 0 )
sdlWindowsize = sdl2.SDL_GetWindowSize( window, WIDTH, HEIGHT )
print('sdlWindowsize = {0}'.format(sdlWindowsize))
错误消息:
Traceback (most recent call last):
File "/home/sunbear/Coding/Vulkan/vulkan/MyProject/LunarG_cube_example/sdl2_window.py", line 13, in <module>
sdlWindowsize = sdl2.SDL_GetWindowSize( window, WIDTH, HEIGHT )
ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_c_int instance instead of int
答案 0 :(得分:0)
SDL_GetWindowSize需要3个参数 - 窗口和两个指向int
的指针,它将保存结果值。它没有返回任何值。由于pysdl2使用ctypes,它应该是例如:
import sdl2
import ctypes
APP_SHORT_NAME = 'Test'
WIDTH = 400
HEIGHT = 400
sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
window = sdl2.SDL_CreateWindow(
APP_SHORT_NAME.encode('ascii'),
sdl2.SDL_WINDOWPOS_UNDEFINED, sdl2.SDL_WINDOWPOS_UNDEFINED,
WIDTH, HEIGHT, 0 )
w = ctypes.c_int()
h = ctypes.c_int()
sdl2.SDL_GetWindowSize( window, w, h)
print("w=%d h=%d" % (w.value, h.value))