SDL_BlitSurface() not displaying image?

Posted by Christian Gonzalez on Stack Overflow See other posts from Stack Overflow or by Christian Gonzalez
Published on 2012-07-09T22:42:37Z Indexed on 2012/07/10 9:15 UTC
Read the original article Hit count: 260

Filed under:
|

So I'm trying to display a simply image with the SDL library, but when I use the function SDL_BlitSurface() nothing happens, and all I get is a black screen. I should also note that I have the .bmp file, the source, and the executable file all in the same directory.

//SDL Header
#include "SDL/SDL.h"

int main(int argc, char* args[])
{
    //Starts SDL
    SDL_Init(SDL_INIT_EVERYTHING);

    //SDL Surfaces are images that are going to be displayed.
    SDL_Surface* Hello = NULL;
    SDL_Surface* Screen = NULL;

    //Sets the size of the window (Length, Height, Color(bits), Sets the Surface in Software Memory)
    Screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    //Loads a .bmp image
    Hello = SDL_LoadBMP("Hello.bmp");
    //Applies the loaded image to the screen
    SDL_BlitSurface(Hello, NULL, Screen, NULL);
    //Update Screen
    SDL_Flip(Screen);
    //Pause
    SDL_Delay(2000);
    //Deletes the loaded image from memory
    SDL_FreeSurface(Hello);
    //Quits SDL
    SDL_Quit();

    return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about sdl