954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SDL how to switch back to console

Hey, im in need of a little help...

im trying to have my .exe show an image with sdl, wait 2500 milliseconds, close the image and then return to the black console screen with my cout statments and whatnot appearing.

But instead when i exit sdl, the whole program exits. is there any way to correct this?

Here's my source code:

//including files here...

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

	SDL_Surface *screen;
	SDL_Surface *picture;
	SDL_Event event;
	SDL_Rect pictureLocation;
	const SDL_VideoInfo* videoinfo; 

	atexit(SDL_Quit);

	/* Initialize the SDL library */
	if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
		fprintf(stderr,"Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	} 

	screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_HWSURFACE);
	if ( screen == NULL ) {
		fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
			SDL_GetError());
		exit(1);
	} 

	videoinfo = SDL_GetVideoInfo();

	printf("%i", videoinfo->blit_hw);

	// Load Picture
	picture = IMG_Load("image.bmp");

	if (picture == NULL) {
		fprintf(stderr, "Couldn't load %s: %s\n", "image.bmp", SDL_GetError());
		return 0;
	} 

	pictureLocation.x = 0;
	pictureLocation.y = 0; 

	SDL_FillRect(screen, NULL, 1000);
		SDL_BlitSurface(picture, NULL, screen, &pictureLocation);
		SDL_Flip(screen); 

		SDL_Delay(2500); 

		exit(0);

//more code that isnt used below, i.e the "cout" statements.
thriek
Newbie Poster
18 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

Very few, if any, members here know what those SDL functions are. Is that a library of some kind? If it is, post the link to it.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

You will have to work with the graphical window, because once you exit
the sdl window, it automatically closes the console window as well. You
might be able to get around this by using win32 but thats another
language you will have to learn.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 
Very few, if any, members here know what those SDL functions are. Is that a library of some kind? If it is, post the link to it.

Do you mean is SDL a library of some kind? Yes it is, and the link is: www.libsdl.org

thriek
Newbie Poster
18 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

I don't know much about SDL programs' behaviour and possibilities, but I noticed that you do a exit(0); there (line #50). In practice, no code that you have below that line will get executed, see exit() .

Perhaps you should find a SDL forum for SDL-specific questions.

mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

I don't know much about SDL programs' behaviour and possibilities, but I noticed that you do a exit(0); there (line #50). In practice, no code that you have below that line will get executed, see exit() .

Perhaps you should find a SDL forum for SDL-specific questions.

Oh yeah! In my mind i was thinking SDL_quit(); which exits sdl.

swapping my exit with the sdl_quit statment fixes the problem. my image loads, holds for a number of seconds, and then the console screen is loaded.

Thanks for the help!

thriek
Newbie Poster
18 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: