   SDL - Why Does This Show Nothing?
  I am learning SDL, but I wasn't really retaining any information. Instead of downloading the source code, etc, I decided to type it myself, because it would help me more.But, even after reviewing my code, I cannot figure out why this just displays a black screen. I have two files called hello_world.bmp and background.bmp.It has worked before, but now it does not.Here is my code:#include "SDL.h"#include "SDL_image.h"#include <string>//Holds screen valuesconst int SCREEN_WIDTH = 640;const int SCREEN_HEIGHT = 480;const int SCREEN_BPP = 32; //bpp = bits per pixel//Surfaces being usedSDL_Surface *message = NULL; //set to null if not pointing to anythingSDL_Surface *background = NULL;SDL_Surface *screen = NULL;SDL_Surface *load_image(std::string filename){//Holds the loaded imageSDL_Surface *loadedImage = NULL;//Optomized imageSDL_Surface* optimizedImage = NULL;//Loads the imageloadedImage = IMG_Load( filename.c_str() );//If image loads, it will no longer be nullif( loadedImage != NULL ){//Optimize the loaded imageoptimizedImage = SDL_DisplayFormat( loadedImage );//Delete old image to prevent memory leakSDL_FreeSurface( loadedImage );}//Return the optimized image so it can be usedreturn optimizedImage;}void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination){//Rectangle that hols offsetsSDL_Rect offset;//Give the offsets to the rectangle so we can apply it to BlitSurfaceoffset.x = x;offset.y = y;//Blit the surfaceSDL_BlitSurface( source, NULL, destination, &offset );}int main( int argc, char* args[] ){//Initialize all SDL subsystemsif( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ){return 1;}//Set up the screenscreen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );//If error occurs while setting up screenif( screen == NULL ){return 1;}//Set the window captionSDL_WM_SetCaption( "The Game", NULL );//Load imagesmessage = load_image( "hello_world.bmp" );background = load_image( "background.bmp" );//Apply background to screenapply_surface( 0, 0, background, screen );//Apply message to screenapply_surface( 180, 140, message, screen );//Update screenif( SDL_Flip( screen ) == -1 ){return 1;}//Wait 2 secondsSDL_Delay( 2000 );//Free the surfaces, prevent memory leakSDL_FreeSurface( message );SDL_FreeSurface( background );//Quit SDLSDL_Quit();return 0;}
  Obvious question - can it find the image? Eg: does IMG_Load succeed?   ;  Check the return value of SDL_BlitSurface().   ;  I see you are on lazyfoo SDL tutorial number 1.Try changing 'IMG_Load' to 'SDL_LoadBMP'.That was a bug one of my games had, when I'd used the image loading function from that tutorial. Also, read this:http://www.libsdl.org/cgi/docwiki.cgi/Introduction_to_SDL_Video;Quote:Original post by BraussI see you are on lazyfoo SDL tutorial number 1.Try changing 'IMG_Load' to 'SDL_LoadBMP'.That was a bug one of my games had, when I'd used the image loading function from that tutorial. You are wrong. Using IMG_Load() is not indicative of a bug. Some other issue manifested itself in your case which caused IMG_Load not to work for you.   ;  IMG_Load and SDL_LoadBMP should both work, but neither do.Edit: I figured out I placed the images in the SDL project folder, when this project had a new name of SDL-game. Simple mistakes can mean so much to your programs.Thanks for the help anyways.[Edited by - InfiniteLoop on May 28, 2009 2:25:43 PM];Quote:Original post by rip-offQuote:Original post by BraussI see you are on lazyfoo SDL tutorial number 1.Try changing 'IMG_Load' to 'SDL_LoadBMP'.That was a bug one of my games had, when I'd used the image loading function from that tutorial. You are wrong. Using IMG_Load() is not indicative of a bug. Some other issue manifested itself in your case which caused IMG_Load not to work for you.Ah, my apologies, and sorry InfiniteLoop!I didn't find IMG_load() in the SDL documentation though, but I'll search harder next time.   ;  It is part of the add-on SDL_Image library, referred to by the line saying #include "SDL_image.h". You need to have that installed to use it.   