Jump to content
  • Advertisement
Sign in to follow this  
pcwaddell

SDL Flicker

This topic is 3671 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!