2017-04-26 58 views
0

我想知道什麼是適當的方式使用SDL_GetWindowSize()。根據我得到的錯誤信息,我不應該使用WIDTH和HEIGHT,因爲它們是整數。那麼應該在他們的地方使用什麼?什麼函數參數應該用於sdl2.SDL_GetWindowSize?

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

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)) 
+0

它應該是'W = ctypes.c_int()'和'H = ctypes.c_int()'呢?我試過這些,他們也工作。使用'w = ctypes.c_int(WIDTH)'和'h = ctypes.c_int(HEIGHT)'給人的感覺是需要將WIDTH和HEIGHT傳遞給SDL_GetWindowSize()來獲得窗口的寬度和高度,似乎很奇怪。 –

+0

沒錯,它只是初始值。在這種情況下無關緊要。但是,是的,將其初始化爲0可能更好。 – keltar

+0

你能更新/修改你的答案嗎? –

相關問題