Jump to content
  • Advertisement
Sign in to follow this  
Auriya

[Solved, I think!] SDL/OpenGL glitching(?) problem

This topic is 2950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again everyone!

I've been learning OpenGL to use with SDL because I'm starting to build up confidence for 3d.
But for now, I'm still sticking to 2D, and I've noticed that the CPU usage is tremendously less than SDL-Only when I use SDL with OpenGL, so I like it very much!

However, as I've put together a quick 2d scrolling map which seems to work very well so far, but there's a minor glitch I'm haunted by. I first thought it might have been the video card not refreshing fast enough, but the other computer seemed to have a pretty similar glitch.

On Windows it seems as if the scrolling is skipping 1~2pixel(s) each second or so, and on OSX it looks a tad worse (see video and screenshot) as the glitch seems to quickly go from the bottom of the game-screen to the top and then disappear.

I have linked to my source code below. The reason I'm not including snippets of code is because I have no idea where I should be looking to perhaps fix this..I tried to mess about with the drawing code and the map-loop-tile-by-tile-drawing (drawMap()) but nothing helped.

If anyone has enough free time and could maybe look at the source to help me out I'd be eternally grateful!
If not, thanks anyway!
Every tip is very welcome!

Small update: In the video the scrolling seems choppy (as if it get stuck or lags heavily) at around the end of the video but it's not. It's going very smooth.
Update#2: Also, when I scroll, it seems to become a tad blurry or fuzzy, is that supposed to happen?

Source: http://bluemelody.info/src.zip
Screenshot: http://i37.tinypic.com/2ahryfn.png
Video:
(Taken with a cam because onscreen recorders didn't seem to somehow notice the glitch(?))

(Sorry for the very rushed post..I have to get to work in a couple so I'm gonna grab some breakfast quick. I'll be watching the thread and updating it if I forgot to include anything..)

Thanks in advance all, cheers!
~j

[Edited by - Auriya on August 23, 2010 1:02:41 PM]

Share this post


Link to post
Share on other sites
Advertisement
Before I give the source code a look I'm assuming it's just shearing because vsync is not working for some reason?

Is it turned off on your video card? I have a GTS-250 and my SDL GL app always seems to be vsynced (I don't believe I set it so in initialization) unless I set 'force vsync off' on my nvidia control panel.

Share this post


Link to post
Share on other sites
Hey!

I have Forced VSync on on my Windows computer through the NVidia Panel (GT 130M - 1GB) and that seemed to have slightly helped, it's not very noticeable when scrolling from left to right, but when scrolling to the bottom left (from top left) it seems to be quite visible quite a bit.

Though on OSX I'd have to check whether VSync is on or not.

Share this post


Link to post
Share on other sites
When I run it I get a consistent tear when moving left/right that stays in one spot but only on 2nd monitor, any part of the screen on the 1st monitor is fine.

But I can't get it to happen for me if I run it in fullscreen.

Share this post


Link to post
Share on other sites
Actually there does appear to be a flickering of the lines at the same spot when moving up and down on the 2nd screen..going to take a look at the drawing functions.

Share this post


Link to post
Share on other sites
Thank you very much for looking into it! I really wonder what I must've done wrong..I'm quite new to OpenGL, sorry if it's something I should've seen coming!

Share this post


Link to post
Share on other sites
Okay I don't have experience with textures yet.

Only one thing I notice is that in my code I call glClear at the beginning of rendering and SDL_GL_Swap_Buffers at the end. In your code it looks like glClear is the last thing called in the loop so there is input/logic happening between the clear and the drawing steps methinks.

But otherwise it seems to run fine with no glitches, I can only get the small glitch mentioned to happen in the strange case of running windowed on a 2nd monitor and I think that might be video card or windows related.

Have you done tests running fullscreen?

I also saw you had some sort of 60 FPS limit built in. Maybe try and let the video card or SDL handle vsync, I think there is an attribute you can set maybe.

Share this post


Link to post
Share on other sites
Hey!

As far as I know glClear clears the screen, so using it after swapping buffers should (I think) be okay, but just in case I moved it to right before drawing, but sadly that didn't help.
Fullscreen also doesn't seem to help, I see the same thing as in Windowed mode.

I do notice that without the 60fps code in place, on Windows it keeps to 60fps (which I think my screen is set to as well,) however on OSX it seems to go haywire over hundreds of fps.
Though even without the fps code and vsync on on my windows computer, the occasional flickering/hang/glitch(?) still seems to happen every now and then, but not as constantly as it does on OSX.

Very strange..I'm really puzzled by this and have no idea what I have to do to solve it..

Thanks you though, I'm really grateful for the help! :)

Big update:
This is very strange. I moved the line:
currentTick = SDL_GetTicks();

All the way below to right before the FPS capping, and printf'd the current FPS and it seems that now, instead of being capped at 63fps, it is now properly capped at 60fps, which seems to get rid of the glitch. However it very often jumps to 61fps, which makes the line/glitch come back until it drops down to 60fps again..so clearly it's the game sometimes refreshing faster than my screen?

Since previously when I had the glitch heavily it was running at 63fps (even though I told it to cap it at 60) due to having misplaced the line of code.

Does that mean I simply have to find a good way to cap the FPS or something else?
Is there a different way to go besides VSync?

Sorry for the questions, I'm just very curious as well as anxious about a solution.

Thanks so far!

~j

[Edited by - Auriya on August 23, 2010 12:28:27 PM]

Share this post


Link to post
Share on other sites
Solved! ..I think.

At least it seems to be so far. I'm gonna throw some more at it to see if it holds up or not..

Added: SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); to the initialization and it seems to have no more problems at all.
This apparently turns on Vsync for the app/game or something in that direction?
I came across it in another thread here: http://www.gamedev.net/community/forums/topic.asp?topic_id=529217

If anyone else knows something, please do let me know!

Thanks for all the help!

~j

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!