The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Problem Using PySDL2 on Gentoo Linux
Andreas Grapentin
Guest

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
Problem Using PySDL2 on Gentoo Linux
Jonas Kulla
Guest

2014-10-02 11:03 GMT+02:00 Andreas Grapentin:
Quote:
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




Instead of drawing everything once and quitting, have your script render the same frame in a loop over
and over again until the user closes it (SDL_QUIT event). It's very likely that your single frame gets stuck

inside some double buffering scheme.
Problem Using PySDL2 on Gentoo Linux
Andreas Grapentin
Guest

On 10/02/2014 12:51 PM, Jonas Kulla wrote:

Quote:
2014-10-02 11:03 GMT+02:00 Andreas Grapentin:
Quote:
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




Instead of drawing everything once and quitting, have your script render the same frame in a loop over
and over again until the user closes it (SDL_QUIT event). It's very likely that your single frame gets stuck

inside some double buffering scheme.






Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for your reply!
I changed my code as you suggested to include an sdl2 event loop:


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)

running = True
while running:
SDL_RenderClear(ren)
SDL_RenderCopy(ren, tex, None, None)
SDL_RenderPresent(ren)

event = SDL_Event()
while SDL_PollEvent(ctypes.byref(event)) != 0:
print "."
if event.type == SDL_QUIT:
running = False
break

SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();


but the observed behaviour does not change.
Problem Using PySDL2 on Gentoo Linux
Andreas Grapentin
Guest

On 10/02/2014 01:58 PM, Andreas Grapentin wrote:

Quote:
On 10/02/2014 12:51 PM, Jonas Kulla wrote:

Quote:
2014-10-02 11:03 GMT+02:00 Andreas Grapentin:
Quote:
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




Instead of drawing everything once and quitting, have your script render the same frame in a loop over
and over again until the user closes it (SDL_QUIT event). It's very likely that your single frame gets stuck

inside some double buffering scheme.






Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for your reply!
I changed my code as you suggested to include an sdl2 event loop:


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)

running = True
while running:
SDL_RenderClear(ren)
SDL_RenderCopy(ren, tex, None, None)
SDL_RenderPresent(ren)

event = SDL_Event()
while SDL_PollEvent(ctypes.byref(event)) != 0:
print "."
if event.type == SDL_QUIT:
running = False
break

SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();


but the observed behaviour does not change.


Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I found my problem - my checks of the return values of the SDL_* functions were faulty, and I was missing an error of the type

"Couldn't find matching render driver"

That is something I can work with. Thanks for the help!