Hello,
I have tried to integrate PySDL2 into a projet of mine, but kept getting
blank windows instead of the desired rendered image. After a couple of
days of poking around the issue, I decided to try the Hello World
example, but even this yields a blank window. I am honestly at a loss
what to try next, and hope you can help =)
below is the code of my simple example script:
|
||
||from sdl2w import *||
||
||SDLW_Init(SDL_INIT_VIDEO)||
||win = SDLW_CreateWindow(“Hello World”, 100, 100, 640, 480,
SDL_WINDOW_SHOWN)||
||ren = SDLW_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED |
SDL_RENDERER_PRESENTVSYNC)||
||
||bmp = SDLW_LoadBMP(‘startup.bmp’)||
||tex = SDLW_CreateTextureFromSurface(ren, bmp)||
||SDL_FreeSurface(bmp)||
||
||SDL_RenderClear(ren)||
||SDL_RenderCopy(ren, tex, None, None)||
||SDL_RenderPresent(ren)||
||
||SDL_Delay(2000)||
||
||SDL_DestroyTexture(tex);||
||SDL_DestroyRenderer(ren);||
||SDL_DestroyWindow(win);||
||SDL_Quit();||
|
where the SDLW_* functions are defined as pass-through functions for
their SDL_* pendants, with added exception handling:
|from sdl2 import *||
||import ctypes||
||
||class SDLW_Exception(Exception):||
|| pass||
||
||def SDLW_Assert(condition):||
|| if not condition:||
|| raise SDLW_Exception(SDL_GetError())||
||
||def SDLW_Init(*args, **kwargs):||
|| res = SDL_Init(*args, **kwargs)||
|| SDLW_Assert(res == 0)||
|| return res||
||
||def SDLW_CreateWindow(*args, **kwargs):||
|| res = SDL_CreateWindow(*args, **kwargs)||
|| SDLW_Assert(res is not None)||
|| return res||
||
||def SDLW_CreateRenderer(*args, **kwargs):||
|| res = SDL_CreateRenderer(*args, **kwargs)||
|| SDLW_Assert(res is not None)||
|| return res||
||
||def SDLW_LoadBMP(*args, **kwargs):||
|| res = SDL_LoadBMP(*args, **kwargs)||
|| SDLW_Assert(res is not None)||
|| return res||
||
||def SDLW_CreateTextureFromSurface(*args, **kwargs):||
|| res = SDL_CreateTextureFromSurface(*args, **kwargs)||
|| SDLW_Assert(res is not None)||
|| return res||
|
and startup.bmp is a simple bitmap file located in the current directory.
Executing the python script opens a blank window, and closes it after
two seconds, instead of displaying in the Image, as I would expect. No
terminal output is produced. I am convinced I must be doing something
wrong, do you have any Ideas?
Thanks,
Andy
System Specs:
gentoo linux on amd64 architecture
libsdl2 version 2.0.3-r100
PySDL2 version 0.9.3