tags:

views:

160

answers:

3

I've tried to follow this tutorial on the basics of displaying an image with SDL. But, when I run the program, it returns a blank screen. The image is in the correct directories, but it doesn't display in the program. Am I doing something wrong? I'd really like SDL to work.

EDIT

Here is my code:

#include <SDL/SDL.h>

using namespace std;

int main(int argc, char *argv[])
{
    SDL_Surface *hello;
    SDL_Surface *screen;
    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
    hello = SDL_LoadBMP("hello.bmp");
    SDL_BlitSurface(hello, NULL, screen, NULL);
    SDL_Flip(screen);
    SDL_Delay(2000);
    SDL_FreeSurface(hello);
    SDL_Quit();
    return 0;
}
+1  A: 

Use SDL_GetError() to find out why SDL_LoadBMP() fails loading your bitmap.
Read this thread too

gabriev82
Thanks, the error it returned was SDL_UpperBlit: passed a NULL surface. What does that mean?
Greg Treleaven
Strange... SDL version and OS?
gabriev82
SDL 1.2, Windows Vista Home Premium x86. Is the tutorial maybe for a different version?
Greg Treleaven
You could try checking with gdb how the surface is formed, does it have correct image data?
Masse
A: 

Make sure that hello.bmp is in your current directory, and that it's a readable and valid BMP file.

Igor Krivokon
Is there a certain format it can only take for the BMP, like 16-bit?
Greg Treleaven
It should support any windows BMP files; if you can see the BMP using a standard Windows viewer, it's good enough. Are you sure you are running the process in the same directory where your hello.bmp is stored? Do you use command line to run your program?
Igor Krivokon
It is in the same directory, and I have tried using the command line and the viewer. Is there any other explanation?
Greg Treleaven
+1  A: 

I thought I said I had fixed this months ago, seems as though I had not. I recompiled it again and it worked, very strange.

Greg Treleaven