Some SDL Issues

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Chaos Clown
ES Beta Backer
ES Beta Backer
Posts: 61
Joined: Sun Sep 21, 2008 4:46 am
Location: U.K.

Some SDL Issues

Post 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.
Last edited by Chaos Clown on Mon Feb 02, 2009 1:59 pm, edited 1 time in total.
¡Sí! ¡He dejado en libertad los prisioneros y ahora vengo por ti!
~El Pollo Diablo
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: Some SDL Issues

Post 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.
There's no place like ~/
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Some SDL Issues

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
programmerinprogress
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 632
Joined: Wed Oct 29, 2008 7:31 am
Current Project: some crazy stuff, i'll tell soon :-)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++!
Location: The UK
Contact:

Re: Some SDL Issues

Post 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
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
---------------------------------------------------------------------------------------
And now a joke to lighten to mood :D

I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
User avatar
Amarant
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Wed Nov 05, 2008 9:52 am

Re: Some SDL Issues

Post 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.
177
User avatar
sparda
Chaos Rift Junior
Chaos Rift Junior
Posts: 291
Joined: Tue Sep 23, 2008 3:54 pm

Re: Some SDL Issues

Post by sparda »

Jesus. I was surprised as to how easy this SDL problem was to solve.

Here is the solution, thank me later :)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Some SDL Issues

Post 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 :)
:lol: :lol:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Chaos Clown
ES Beta Backer
ES Beta Backer
Posts: 61
Joined: Sun Sep 21, 2008 4:46 am
Location: U.K.

Re: Some SDL Issues

Post 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)?
¡Sí! ¡He dejado en libertad los prisioneros y ahora vengo por ti!
~El Pollo Diablo
User avatar
Amarant
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 34
Joined: Wed Nov 05, 2008 9:52 am

Re: Some SDL Issues

Post by Amarant »

Chaos Clown wrote:
Amarant wrote: 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).
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.
177
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Some SDL Issues

Post by MarauderIIC »

So in short try enabling vsync.
As for your slowdown, you probably have horrible implementation happening somewhere. Post some code?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Some SDL Issues

Post 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?
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: Some SDL Issues

Post 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.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
Chaos Clown
ES Beta Backer
ES Beta Backer
Posts: 61
Joined: Sun Sep 21, 2008 4:46 am
Location: U.K.

Re: Some SDL Issues

Post by Chaos Clown »

Here's a screenshot. I'll have a look at double buffering. (It is screen tearing, I'm such an idiot :oops: )

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.
Attachments
ScreenShot.png
ScreenShot.png (141.34 KiB) Viewed 1214 times
¡Sí! ¡He dejado en libertad los prisioneros y ahora vengo por ti!
~El Pollo Diablo
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Some SDL Issues

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Some SDL Issues

Post 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...
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply