Page 1 of 2
Some SDL Issues
Posted: Mon Feb 02, 2009 11:08 am
by Chaos Clown
So, I've been building a little platformer to help me learn SDL. Unfortunately, I've been having a couple of issues.
1) I'm not sure how best to describe this, and I can't seem to catch it to take a screenshot of it, but when the sprites move across the screen, sometimes the rows of pixels are out of alignment, and it flickers a bit, sort of like scan lines are being drawn over it. Does anybody know what causes this, and/or how to fix it?
2) Second, it runs slow, REALLY slow, especially when my laptop isn't plugged in (I have a 2.2GHz processor and 2Gigs of RAM, and I sometimes struggle to get 40fps). I'm not really asking for any direct fixes here, just some general optimisation tips. (On this topic, is loading PNGs with SDL image faster than loading BMPs with regular old SDL?)
Thanks.
Re: Some SDL Issues
Posted: Mon Feb 02, 2009 11:27 am
by LeonBlade
Yeah... I don't think it should be running that slow LOL...
I just set up SDL on my computer with Visual C++ 2008 Express Edition...
Let me see your source.
Re: Some SDL Issues
Posted: Mon Feb 02, 2009 4:22 pm
by MarauderIIC
Chaos Clown wrote:1) I'm not sure how best to describe this, and I can't seem to catch it to take a screenshot of it, but when the sprites move across the screen, sometimes the rows of pixels are out of alignment, and it flickers a bit, sort of like scan lines are being drawn over it. Does anybody know what causes this, and/or how to fix it
I had an issue that sounds kind of similar. I had a chessboard png that I made with an older version of gimp and every time it was drawn or loaded in a different editor it was slanted. If you're using gimp, update or use something else, perhaps.
Re: Some SDL Issues
Posted: Mon Feb 02, 2009 4:26 pm
by programmerinprogress
Chaos Clown wrote: (On this topic, is loading PNGs with SDL image faster than loading BMPs with regular old SDL?)
I'm not quite sure, but I can probably guess so, due to the smaller file sizes of the PNG, I always use IMG_Load instead of LoadBMP
Re: Some SDL Issues
Posted: Mon Feb 02, 2009 4:48 pm
by Amarant
Chaos Clown wrote:
1) I'm not sure how best to describe this, and I can't seem to catch it to take a screenshot of it, but when the sprites move across the screen, sometimes the rows of pixels are out of alignment, and it flickers a bit, sort of like scan lines are being drawn over it. Does anybody know what causes this, and/or how to fix it?
Not sure, but it seems like you're describing tearing:
http://en.wikipedia.org/wiki/Screen_tearing.
Re: Some SDL Issues
Posted: Mon Feb 02, 2009 4:56 pm
by sparda
Jesus. I was surprised as to how easy this SDL problem was to solve.
Here is the solution, thank me later
Re: Some SDL Issues
Posted: Mon Feb 02, 2009 6:16 pm
by dandymcgee
sparda wrote:Jesus. I was surprised as to how easy this SDL problem was to solve.
Here is the solution, thank me later
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 2:04 am
by Chaos Clown
Amarant wrote:Chaos Clown wrote:
1) I'm not sure how best to describe this, and I can't seem to catch it to take a screenshot of it, but when the sprites move across the screen, sometimes the rows of pixels are out of alignment, and it flickers a bit, sort of like scan lines are being drawn over it. Does anybody know what causes this, and/or how to fix it?
Not sure, but it seems like you're describing tearing:
http://en.wikipedia.org/wiki/Screen_tearing.
I read that a little while ago, I don't think that's it, since it only seems to affect moving sprites (the player and enemies).
Marauder - I only used GIMP for the background, so I'm not sure that's the problem. I'll try changing it though, see if it makes a difference.
I'll play around with the code tonight after college, hopefully the answer will be glaringly obvious after not looking at it for a while (it usually is).
Any Ideas about the slowdown, or is it just my computer (running vista)?
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 5:26 am
by Amarant
Chaos Clown wrote:
I read that a little while ago, I don't think that's it, since it only seems to affect moving sprites (the player and enemies).
As far as I can tell the reason you say it isn't tearing is in fact the reason it is tearing.
Tearing can only be seen with moving sprites.
It occurs when the screen displays two different gamestates/frames at the same time, the top half being the older of the two.
Non moving objects will be in the same position in both of the halves and that's why you won't see them tear.
edit:
Hmm, re-read your post and now I'm not sure what you mean by 'it'. If by 'it' you mean tearing, ignore the above, otherwise it still applies.
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 8:49 am
by MarauderIIC
So in short try enabling vsync.
As for your slowdown, you probably have horrible implementation happening somewhere. Post some code?
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 8:59 am
by Falco Girgis
I want to see a screenshot to see what you're rendering, then I would probably need to see how you're rendering it.
For the flickering, you are double buffering, right?
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 9:33 am
by M_D_K
GyroVorbis wrote:I want to see a screenshot to see what you're rendering, then I would probably need to see how you're rendering it.
For the flickering, you are double buffering, right?
I doubt it. Flickering would likely be the result of using a single buffer. As for the the "scan line" thing, it might just be that you screen refresh rate is too low. If its LCD I've seen what your talking about, and you can't get a screenshot since eveything in the screens buffer is fine.
Hmm all that is a bit conflicting.
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 10:42 am
by Chaos Clown
Here's a screenshot. I'll have a look at double buffering. (It is screen tearing, I'm such an idiot
)
Thanks for the help everyone.
EDIT: I tried the whole double buffering thing - It made little to no difference. It may just be my laptop screen, since I can't grab a screenshot of it, no matter how hard I try.
EDIT EDIT: Also, about the slowdown. I found the source of the problem (a bug in the text system, it shouldn't be too hard to fix).
EDIT EDIT EDIT: Removing the text reduces the tearing a LOT. It's almost unnoticable now.
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 2:32 pm
by MarauderIIC
Are you drawing everything to the backbuffer, not the frontbuffer? If you're drawing to the front buffer and you flip you wouldn't have any difference =) I'm not even sure you can do that in SDL, though.
Re: Some SDL Issues
Posted: Tue Feb 03, 2009 2:51 pm
by Ginto8
MarauderIIC wrote:Are you drawing everything to the backbuffer, not the frontbuffer? If you're drawing to the front buffer and you flip you wouldn't have any difference =) I'm not even sure you can do that in SDL, though.
LusikkaMage doubled-buffered her music-showing program...