Sign in to follow this  

SDL Flicker

This topic is 3342 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! Im pretty new to SDL, i was able to get an image loaded but for some reason it is flashing constantly. I tried adding "SDL_DisplayFormat()","SDL_UpdateRect()" and changing some other things that i thought would fix it but nothing. I also tried changing the flags, i tried to set the video mode fullscreen, window, SWSURFACE, HWSURFACE,etc.
#include "SDL/SDL.h"



int main( int argc, char* args[] )
{

    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
    const int SCREEN_BPP = 32; 

	//Start SDL 
	SDL_Init( SDL_INIT_EVERYTHING );

 
    SDL_Surface *screen = NULL;
    SDL_Surface *pic = NULL;
    SDL_Surface *newPic = NULL; 
    SDL_Rect dstRect;

    int done =0;

    while(done == 0)
    {  


	
        //Event initialization 
        SDL_Event event;

       //loops program
       while ( SDL_PollEvent(&event) )
       {   


		   //x button ends program
           if ( event.type == SDL_QUIT )  
		   { 
			   done = 1; 
		   }

           if ( event.type == SDL_KEYDOWN )
           {  //esc key ends program
              if ( event.key.keysym.sym == SDLK_ESCAPE )
			  {
				  done = 1;
			  }
           }
       }

	   //set video mode
	   screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_FULLSCREEN|SDL_HWSURFACE);

       //load image
       pic = SDL_LoadBMP("zeldaBMP.bmp");
       newPic = SDL_DisplayFormat( pic );
	   dstRect.y = 80;
	   dstRect.x = 80;

       //blit image
       SDL_BlitSurface(newPic,NULL,screen,&dstRect);
       SDL_UpdateRect(screen,0,0,screen->w,screen->h);
       SDL_Flip(screen);

       //Set the window caption 
	   SDL_WM_SetCaption( "Hello World", NULL ); 
     }

	 //Quit SDL 
	 atexit(SDL_Quit);

	 return 0; 
} 


Share this post


Link to post
Share on other sites
I'm not sure, but I think the call to SDL_SetVideoMode() and the loading of the image should be outside the main loop.

Try something like.


#include "SDL/SDL.h"

int main( int argc, char* args[] )
{

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );


SDL_Surface *screen = NULL;
SDL_Surface *pic = NULL;
SDL_Surface *newPic = NULL;
SDL_Rect dstRect;

//set video mode
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_FULLSCREEN|SDL_HWSURFACE);

//load image
pic = SDL_LoadBMP("zeldaBMP.bmp");
newPic = SDL_DisplayFormat( pic );
dstRect.y = 80;
dstRect.x = 80;

int done =0;

while(done == 0)
{
//Event initialization
SDL_Event event;

//loops program
while ( SDL_PollEvent(&event) )
{


//x button ends program
if ( event.type == SDL_QUIT )
{
done = 1;
}

if ( event.type == SDL_KEYDOWN )
{ //esc key ends program
if ( event.key.keysym.sym == SDLK_ESCAPE )
{
done = 1;
}
}
}



//blit image
SDL_BlitSurface(newPic,NULL,screen,&dstRect);
SDL_UpdateRect(screen,0,0,screen->w,screen->h);
SDL_Flip(screen);

//Set the window caption
SDL_WM_SetCaption( "Hello World", NULL );
}

//Quit SDL
atexit(SDL_Quit);

return 0;
}

Share this post


Link to post
Share on other sites
Dude your a genius, it worked. lol. I made that loop so it wouldnt close the program, not realizing that its just reloading it every second. thank you :)

Share this post


Link to post
Share on other sites

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