Advertisement Jump to content
Sign in to follow this  
Alpha Nox

SDL Library, Video init

This topic is 4932 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 again, I finally installed SDL successfully but I'm now having other problem. I'm reading the SDL documentation and what I tried to do was show a BMP but, I init sdl video ok, and then I show a bmp. It all works fine but when I show the bmp, after about 2 or 3 seconds the SDL SCREEN initialized becomes white and kinda crashes. I read the documentation but found nothing about it. I'm using the following code: // CODE START #include "stdafx.h" #include "windows.h" #include <stdlib.h> #include <SDL.h> using namespace std; void ShowBMP(char *file, SDL_Surface *screen, int x, int y); int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } // atexit(SDL_Quit); SDL_Surface *screen; { screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Unable to set 800x600 video: %s\n", SDL_GetError()); exit(1); } } system("pause"); ShowBMP("C:\\baldurgate.bmp",screen, 0,0); system("pause"); return 0; } void ShowBMP(char *file, SDL_Surface *screen, int x, int y) { SDL_Surface *image; SDL_Rect dest; /* Load the BMP file into a surface */ image = SDL_LoadBMP(file); if ( image == NULL ) { fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); return; } /* Blit onto the screen surface. The surfaces should not be locked at this point. */ dest.x = x; dest.y = y; dest.w = image->w; dest.h = image->h; SDL_BlitSurface(image, NULL, screen, &dest); /* Update the changed portion of the screen */ SDL_UpdateRects(screen, 1, &dest); } // CODE END Thanks very much for you help, Victor Freire

Share this post

Link to post
Share on other sites
From a quick glance t your code:
For one thing you should uncomment the atexit(SDL_Quit) line, it looks like you're app is never calling SDL_Quit()

Or you could get rid of the system("pause"); and replace it with this

SDL_Event event;

while(SDL_PollEvent(&event)){ /* Loop until there are no events left on the queue */
switch(event.type){ /* Process the appropiate event type */
case SDL_QUIT: /* Handle a QUIT event */

However, if you do that, you don't need the atexit(). Make sure SDL_Quit() is only being called once.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!