Chinasky
Posts: 4
Joined: Fri Apr 10, 2015 9:18 am

Tearing in pygame using HWSURFACE

Fri Apr 10, 2015 4:04 pm

Hi,
I create a simple game using this screen parameters:

os.environment['SDL_VIDEODRIVER']="fbcon"
pygame.init()
screen = pygame.display.set_mode((720,1280 ), pygame.FULLSCREEN | pygame.HWSURFACE)

It's flickering a lot, if I remove HWSURFACE it stops but it's quite slow.
I'm using a raspberry pi 1 Model b. I also add gpu_mem=256 to try to increase the video mem, but nothing changed.
Any good advice?

thanks a lot
Last edited by Chinasky on Mon Apr 20, 2015 6:47 am, edited 1 time in total.

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: Flickering in pygame using HWSURFACE

Fri Apr 10, 2015 7:31 pm

I have no experience with HWSURFACE.* Are you sure that it is really speeding up your program? I ask this because the Pygame documentation actually discourages using HWSURFACE: "Hardware surfaces are more trouble than they’re worth." https://www.pygame.org/docs/tut/newbieguide.html It is recommned to stick with the software surface. You can't do fast whole screen scrolling but you should be able to move quite a lot of sprites.


* Or, maybe I tried it once but gave up very soon. It was not on the Pi but on a x86 Linux system, so I moved on to Pyglet.

Chinasky
Posts: 4
Joined: Fri Apr 10, 2015 9:18 am

Re: Flickering in pygame using HWSURFACE

Wed Apr 15, 2015 5:05 pm

HI,
thanks for your answer. Indeed I have removed the HWSURFACE and now it works fine.
I tried the new Raspberry Pi 2 and now it runs even faster, but I still have flickering problems in scrolling big sprites, it's like having vsync or duoble buffer might fix the issue. I'm a newbie in pygame/python so I don't have idea how can I force it.
Any idea?

thanks

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Flickering in pygame using HWSURFACE

Wed Apr 15, 2015 5:36 pm

Have a look here https://www.pygame.org/docs/tut/newbieguide.html and read about dirty rect animation. This only updates areas of the screen that have actually changed instead of updating the whole thing.

Dave.
Apple say... Monkey do !!

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: Flickering in pygame using HWSURFACE

Sun Apr 19, 2015 12:49 am

Chinasky wrote: I tried the new Raspberry Pi 2 and now it runs even faster, but I still have flickering problems in scrolling big sprites, it's like having vsync or duoble buffer might fix the issue. I'm a newbie in pygame/python so I don't have idea how can I force it.
thanks
Yes, vsync would fix tearing but it is not available with software surfaces. You probably should forget about vsync with pygame and accept some degree of tearing. You can limit your game's fps close to the refreshing rate of your display (or half of it), but it is not very exact.

I'm not sure what you mean with 'flickering'. If it means 'flashing on and off', I don't think that that would be normal when using software surfaces.

You could install the game solarwolf on your pi 2, just to see what is possible with Pygame. It is made by the guy who started the Pygame project. I don't think that it uses hardware surfaces (at least on Linux systems). There is quite a lot of action on the screen but not any big sprites. Maybe tearing becomes easily visible with bigger moving sprites but is not so noticeable with smaller sprites.

davef21370 mentioned updating only the parts of the surface which have actually changed. The more pixels to update on the screen, the more CPU cycles it takes. I noticed that this also applies to drawing shapes on the screen: Drawing a big filled rectangle demands more from the CPU than drawing a small filled rectangle. I have not tested this, but it could very well apply to blitting also. (This means also that if your game is on a smaller resolution screen, it will be easier on the CPU. Unfortunately I don't think that you can change fullscreen resolution on the fly with the PI.) So, with Pygame you have to be economical in designing a game, and minimize the amount of pixels that needs to be drawn, blitted and updated with every frame.

Chinasky
Posts: 4
Joined: Fri Apr 10, 2015 9:18 am

Re: Flickering in pygame using HWSURFACE

Mon Apr 20, 2015 6:46 am

Hi thanks a lot for your reply.
Indeed what I meant is tearing, sorry. And it happens most likely because I'm using very big sprite. In fact the tearing appears on the big sprites not on the smaller one. Anyway I'm trying to fix the issue drawing only what is actually changed on the screen, but I doubt it will fix completely the issue. I'm working at 30fps at 720x1280. I think I'll be forced to lower down the resolution to avoid completely the issue.

gordon77
Posts: 5036
Joined: Sun Aug 05, 2012 3:12 pm

Re: Tearing in pygame using HWSURFACE

Mon Apr 20, 2015 7:03 am

Any chance of seeing the code ?

Return to “Python”