SDL - FLICKERING!

Started by
9 comments, last by 3Dgonewild 17 years, 1 month ago
Hi , im having a problem with SDL library. Each time i move an image sdl flickers. I've set up the video mode like this: 800,600,32,SW_DOUBLEBUF|SDL_FULLSCREEN Also , i've tryed with the following flags : SW_DOUBLEBUF|SW_HWSURFACE|SDL_FULLSCREEN AND: SW_DOUBLEBUF|SW_SWSURFACE|SDL_FULLSCREEN But nothing. Any ideas?!
Advertisement
The following flags won't work at least: SW_DOUBLEBUF|SW_SWSURFACE|SDL_FULLSCREEN because only SW_HWSURFACE is valid with SW_DOUBLEBUF. The other one should work however. If you post the rest of the code then maybe I can help you. I can't tell what's wrong with this information alone.
Without seeing any other code, it'd be hard to tell. However, I did have an issue when I redrew the entire screen everytime a sprite moved. I got a flicker type effect then. If this is how you're handling your sprites, you can try just updating what needs to be redrawn.

For example, if you have a sprite that is 32x32, you would only redraw that 32x32 area anytime it moves instead of redrawing the entire 800x600 screen.
try calling SDL_GL_SwapBuffers() or SDL_SwapBuffers(); in your gameloop.
I'v seen that sometimes when SDL_Flip is called at the wrong moment, or called more than once in your loop process.
Thanks for the support.

The image is about 200 x 200 ( its a bouncing ball ).


And here's the loop:
(It looks messy , but im just a newbie)
    while( quit == false )    {SDL_Flip( screen );SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );apply_surface( BallX , BallY, _BALL, screen );    fps.start();BallX+=(int)SpeedX;BallY+=BallSpeedY;Bleft=BallX+_BALL->w;Btop=BallY+_BALL->h;    if ( (Btop>SCREEN_Y))     {     BallSpeedY*=-1;     }     if (Btop<SCREEN_Y)     {      BallSpeedY+=1;     }while( SDL_PollEvent( &event ) )        {if( event.type == SDL_KEYDOWN )            {                 switch( event.key.keysym.sym )                {                    case SDLK_UP: SpeedX+=0.2f; break;                    case SDLK_DOWN: SpeedX-=0.2f;break;                //    case SDLK_LEFT:  break;                  //  case SDLK_RIGHT:  break;                     case SDLK_ESCAPE:quit=true;  break;                    }            }                         if( event.type == SDL_QUIT )            {                //Quit                quit = true;            }        }         //FRAMES_PER_SECOND = 20        while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )        {               // LOCK @ 20 FPS        }    }    SDL_Quit();    return 0;    }

I tested your code and it worked fine for me. There were no flicker at all, but the object is shaking when it moves. This is because you have a frame limit to 20 FPS. Change this to 40 or something higher and the movement should be much smoother than before.
Quote:Original post by password
I tested your code and it worked fine for me. There were no flicker at all, but the object is shaking when it moves. This is because you have a frame limit to 20 FPS. Change this to 40 or something higher and the movement should be much smoother than before.


Thanks , now its much better.

By the way , do you know any function(in sdl) that allows you to rotate 2D images ?
I want to add some scrolling effects , but i stuck..
There is an extension library called SDL_gfx that makes this possible. Here is a thread about it: http://www.gamedev.net/community/forums/topic.asp?topic_id=360731
Be carefull with SDL_gfx because this is all done in software mode and if you use it too much it can slow down your game a bit.

This topic is closed to new replies.

Advertisement