Reputation: 29
I have a problem with SDL. When i run the following code it is not responding. I have .bmp in same folder as the executable file.Is problem in code or where.....?
#include "SDL/SDL.h"
int main( int argc, char* args[] )
{
SDL_Surface* robot = NULL;
SDL_Surface* screen = NULL;
SDL_Init( SDL_INIT_EVERYTHING );
screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
robot = SDL_LoadBMP( "robot.bmp" );
SDL_BlitSurface( robot, NULL, screen, NULL );
SDL_Flip( screen );
SDL_Delay( 12*1000 );
SDL_FreeSurface( robot );
SDL_Quit();
return 0;
}
Upvotes: 0
Views: 1617
Reputation: 22890
SDL_Delay( 12*1000 );
will halt the current thread for 12 seconds. The issue is that the thread which is halted is the "video" thread, the one in charge of displaying your image. After 12 secons the window will close and the program will exit.
In order to see the image and exit at will, you need to wait on a specific event of your choice like a keyboard event. See here how to make basic event loop with SDL.
Upvotes: 3