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);
开发者_如何学PythonSDL_FreeSurface(hello);
SDL_Quit();
return 0;
}
Use SDL_GetError() to find out why SDL_LoadBMP() fails loading your bitmap.
Read this thread too
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.
Instead of SDL_Flip(screen)
try using SDL_UpdateRect(screen,0,0,0,0)
Make sure that hello.bmp
is in your current directory, and that it's a readable and valid BMP file.
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.
精彩评论