Sign in to follow this  

[SDL] Quick question about Marius' tutorial. Setting the video mode

This topic is 4200 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

Hi all! I'm following this tutorial for GFX with SDL: http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut3 In that tutorial, he does the following for setting the video mode: screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_HWPALETTE); I would like to use a hw surface instead, so I did this: screen=SDL_SetVideoMode(800,600,32,SDL_HWSURFACE|SDL_DOUBLEBUF); That works great. However, if I try to run it in full screen by doing screen=SDL_SetVideoMode(800,600,32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN); Everything flickers a lot. Do you guys know how I can resolve that problem? I have tried with different parameters but I haven't had any luck. One more thing, do I really need to add SDL_DOUBLEBUF for hw surfaces? If I don't do it, evertythings runs much faster, but it still flickers. Thanks a lot for your help.

Share this post


Link to post
Share on other sites
Typically, flickering occurs when double buffering is not done properly. When you're updating the screen directly (moving rectangles one at a time), you get this funny flicker effect. Try posting some code, maybe there's something obvious.

Also, you can call SDL_VideoModeOK to check whether the combination you're asking for is supported... but there's really no reason for 800x600x32 doublebuf/fullscreen not to be supported :).

EDIT: you can also check SDL_GetVideoInfo to see if your hardware supports various types of blits and whatnot... still, those things don't really relate to flickering, unless we define the term differently.

Share this post


Link to post
Share on other sites
Thanks for your answer, Replicon. I tried the functions that you mentioned and it seems that video mode is correct.

The source code has been taken from here:

Source Code

I still cannot figure out what is wrong...

Share this post


Link to post
Share on other sites
Ah, I'm assuming the cone3d stuff hasn't changed. I remember going through that same tutorial about 2-3 years ago or so, when I first played around with it. It worked perfectly fine for me.

Did you try downloading the source from his link and building that directly? It might work... and then you can diff the two.

Share this post


Link to post
Share on other sites
I'll give it a whirl when I get home. In the mean time, have a look at the comments section, the word 'flicker' shows up a lot, but they seem to be talking more about the thing not executing at all.

Share this post


Link to post
Share on other sites
hey, thanks for that.
I found the solution there.

However, let me ask you something. If I am using a hw surface, do I really need to add SDL_DOUBLEBUF to the video mode?. If I don´t use it, everything runs much much faster but it flickers. On the other hand, I don´t need SDL_DOUBLEBUF for sw surfaces.

Share this post


Link to post
Share on other sites
Double buffering draws everything to an offscreen surface and then flips it to the visual surface all at once instead of drawing each thing on the visual screen as you call SDL_BlitSurface.

When you don't buffer your drawing you will see flicker or tearing because although it is happening quickly you still pick up the drawing order of things to the screen (especially the 2nd layer of sprites).

Conversely the "flipping" done with buffering is more like a movie of frames and eliminates the "flicker" by doing the drawing in the background and just showing you the new image all at once instead of a piece at a time.

Sorry, that sounds repetetive and all, kind of tired. I will try to revise it later.

Share this post


Link to post
Share on other sites
And if you're NOT double buffering, then to get rid of the flicker, you'd have to draw everything to anb off-screen, screen-size surface, and blit the whole thing to the screen... which is basically double buffering, but with an extra screen blit :-).

The only disadvantage of double buffering is that if you're updating the off-screen buffer by means of "dirty rectangle updates", you will have to keep track of dirty rectangles/backgrounds for 2 frames back instead of just one (since you update a given buffer once every other frame).

Share this post


Link to post
Share on other sites

This topic is 4200 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this