sdl, loading and displaying pictures?

i have managed to initialize a program and such in sdl, but i cant seem to find out how to load and display a picture to the screen.

this is my code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "sdl.h"

int main( int argc, char* args[] ){
	SDL_Surface* hello = NULL;
	SDL_Surface* screen = NULL;

	SDL_Init ( SDL_INIT_EVERYTHING );
	SDL_WM_SetCaption ("hello world!", NULL);

	screen = SDL_SetVideoMode (648, 480, 32, SDL_SWSURFACE);
	hello = SDL_LoadBMP ("hello.bmp");
	SDL_BlitSurface (hello, NULL, screen, NULL);
	SDL_Flip ( screen );

	SDL_Event event;
	bool cary_on = true;

	while(cary_on == true){
		while(SDL_PollEvent ( &event )){
			if (event.type == SDL_QUIT){
				cary_on = false;
			}
		}
	}

	SDL_Quit();
	return 0;
}


i cant seem to figure out the fault with this code, and there are no compiling errors either. how can i display a picture?
is SDL_LoadBMP failing? This might happen if it can't find your .bmp file.

Check to see if hello is NULL after the SDL_LoadBMP call.
how do i check that?
why wont it work? i have tried almost every possible way now (i have tried like 10-20 different pathes, one of them being: c:\\users\\evse\\pictures\\hello.bmp) nothing seems to work...

anyone have any idea how to make it work?
It looks in the current directory, which can be one of a few places.

1) If you are running the exe from Windows, the current directory is probably the same directory as the exe itself.

2) If you are running from your IDE (through the debugger), the current directory is probably your project directory or one of its subdirectories.


If you still can't figure it out, you can supply the full path to SDL_LoadBMP:

hello = SDL_LoadBMP ("C:/your/path/to/the/file/hello.bmp");



EDIT:

or if you want to know the current directory, on Windows you can use the GetCurrentDirectory function:

1
2
3
4
5
char buffer[MAX_PATH];

GetCurrentDirectoryA(MAX_PATH,buffer);

cout << "The current directory is:  " << buffer;
Last edited on
haha, thanks for taking the time to answer :D i managed to find the problem myself. it was a problem with the filetype. the file was a jpeg file with a bmp extension, so it worked when i changed it to a bmp file.

btw. i am sorry for making a new thread. i can be very impatient sometimes. it wont happen again.
Topic archived. No new replies allowed.