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; } 
6
  • I don't know if you are doing anything wrong as you haven't posted any code Commented Jun 8, 2010 at 16:36
  • Can we see your exact program? Commented Jun 8, 2010 at 16:36
  • Not sure if this is relevant, but the tutorial states that "Some Linux users will run and get a blank screen. Try running the program from the command line." Commented Jun 8, 2010 at 17:19
  • 1
    For what it's worth, this exact code works correctly on my system (an old version of Ubuntu). Commented Jun 8, 2010 at 17:19
  • it works for me (Mandriva 2011) Commented Dec 5, 2011 at 20:02

5 Answers 5

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

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

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.

Comments

1

Instead of SDL_Flip(screen) try using SDL_UpdateRect(screen,0,0,0,0)

Comments

0

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

3 Comments

Is there a certain format it can only take for the BMP, like 16-bit?
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?
It is in the same directory, and I have tried using the command line and the viewer. Is there any other explanation?
0

In the line: "hello = SDL_LoadBMP("hello.bmp");" , try "/hello.bmp" instead of "hello.bmp". I had the same problem but it seems that putting the slash ("/") before the file name helps in find and therefore, render the image, even if it isn't on the same directory as the program.

If you are on Windows the instead of "/hello.bmp", write "c://hello.bmp". The first one was for Mac. (:

EDIT: Forget it, I just realized it actually doesn't work, it worked for me since I had the file on my disk directory.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.