SDL wrong draw a image

Hey there guys.
Ive just started to learn SDL, and im having a bit of a small problem, im following this tutorial http://lazyfoo.net/SDL_tutorials/lesson01/index2.php the tutorial gets you to draw a simple image to the screen, Now the code i have draws a window but doesnt seem to draw the image,
Im using Visual Studio 2010 C++ express edition,
here is the code

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
#include "SDL.h"
#include <iostream>

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

	//Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );
    //Set up screen
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
    //Load image
	hello = SDL_LoadBMP("hello.bmp");
	//Apply image to screen
    SDL_BlitSurface(hello, NULL, screen, NULL);
    //Update Screen
    SDL_Flip(screen);
    //Pause
    SDL_Delay(2000);
	//Free the loaded image
    SDL_FreeSurface(hello);
    //Quit SDL
    SDL_Quit();
    return 0;    
}


Also im using 1.2.15 SDL, the newest version
also how i add a new image to visual studio is, right click on resources folder -> add existing file -> import my hello.bmp

I have the code working for a 1.2.14 SDL but why isnt it working for SDL 1.2.15? does anyone know what big different there is between the versions?

Thank you so much
Canvas
also how i add a new image to visual studio is, right click on resources folder -> add existing file -> import my hello.bmp


This step does nothing for you. All that does is add the bitmap as a resource, but the code you have there reads the bitmap from the actual file, not a resource.

If it's not working, the thing to check would be to make sure you have the filename right. Also, make sure the file is in the right directory.

Visual Studio typcially makes the working directory the project directory (not the directory the exe is in, but the one the project file is in). Try putting the bitmap in that directory.

Or, as a sanity check, you can put the full path to the bitmap in your code:

 
hello = SDL_LoadBMP("c:/path/to/your/bitmap/hello.bmp");


If that works, but "hello.bmp" doesn't, then you know that hello.bmp is in the wrong directory.
Thank you, its been a pain in my butt :(,
cheers, but quickly, when i go to the debug folder, it doesnt have the .bmp file inside and when i run the exe, it doesnt display the image, but it does display if i run the program in visual studio
Last edited on
That's because it's looking in different directories.

When you run it from visual studio, it's looking in the project directory.
When you run the exe by itself, it's looking in the exe directory.
Topic archived. No new replies allowed.