Starting with SDL, can't load BMP :(
hi guys, I am starting on SDL ( using C ) . I followed some tutorials, but I haven't been able to load an image.
This is the code ( Using Xcode )
when I go for compile and run, the screen turns black, and no image loads... then I get
"[Session started at 2007-01-16 20:17:27 -0300.]
Unable to load bitmap: Couldn't open image.bmp
program has exited with status 1."
I placed the image.bmp in the same directory as main.c, that's inside the proyect folder... can someone help me ?
This is the code ( Using Xcode )
Code:
#include "stdlib.h"
#include "SDL/SDL.h"
int main(int argc, char *argv[])
{
SDL_Surface *screen; //This pointer will reference the backbuffer
SDL_Surface *image; //This pointer will reference our bitmap sprite
SDL_Surface *temp; //This pointer will temporarily reference our bitmap sprite
SDL_Rect src, dest; //These rectangles will describe the source and destination regions of our blit
//We must first initialize the SDL video component, and check for success
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
//When this program exits, SDL_Quit must be called
atexit(SDL_Quit);
//Set the video mode to fullscreen 640x480 with 16bit colour and double-buffering
screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
if (screen == NULL) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
//Load the bitmap into a temporary surface, and check for success
temp = SDL_LoadBMP("image.bmp");
if (temp == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
//Convert the surface to the appropriate display format
image = SDL_DisplayFormat(temp);
//Release the temporary surface
SDL_FreeSurface(temp);
//Construct the source rectangle for our blit
src.x = 0;
src.y = 0;
src.w = image->w; //Use image->w to display the entire width of the image
src.h = image->h; //Use image->h to display the entire height of the image
//Construct the destination rectangle for our blit
dest.x = 100; //Display the image at the (X,Y) coordinates (100,100)
dest.y = 100;
dest.w = image->w; //Ensure the destination is large enough for the image's entire width/height
dest.h = image->h;
//Blit the image to the backbuffer
SDL_BlitSurface(image, &src, screen, &dest);
//Flip the backbuffer to the primary
SDL_Flip(screen);
//Wait for 2500ms (2.5 seconds) so we can see the image
SDL_Delay(2500);
//Release the surface
SDL_FreeSurface(image);
//Return success!
return 0;
}when I go for compile and run, the screen turns black, and no image loads... then I get
"[Session started at 2007-01-16 20:17:27 -0300.]
Unable to load bitmap: Couldn't open image.bmp
program has exited with status 1."
I placed the image.bmp in the same directory as main.c, that's inside the proyect folder... can someone help me ?
You need to place the image next to the built application, for SDL.
Oh, that's great, ill check it out tomorrow.
Quick question... if I want to build a self contained package ( so I don't use external folders for images and all that stuff... ) what should I do ?
Quick question... if I want to build a self contained package ( so I don't use external folders for images and all that stuff... ) what should I do ?
There's something you can change in SDLMain.c ... I can't remember what, but I think it's pretty obvious.
Where should I place the SDLMain.c ???
I downloaded the extras pack from the SDL main URL, but I just installed the Xcode templates... don't have any idea of where to install the SDL main stuff
I downloaded the extras pack from the SDL main URL, but I just installed the Xcode templates... don't have any idea of where to install the SDL main stuff
Just include SDLMain.m and SDLMain.h in your project, in the usual manner.
Oh ok , great, I think they come included in the templates
Guys, about the initial post... I cant load the image 
I am working with Xcode, and when I hit compile and run... all I get is a black screen, and then my error message that I added in
I get
libro has exited with status 1.
[Session started at 2007-01-17 19:15:51 -0300.]
Unable to load bitmap: Couldn't open image.bmp
( all of this in Xcode... I don't know what is wrong... it must be something really stupid I think... I took the image.bmp to the project directory )
, if anyone can help me , it would be great!
I really want to get into this,
#########EDIT#######
Guys I managed to load the image specifying the whole path like this
Is there an easier way of doing this instead of always specifying the whole path ??
Thanks!!!

I am working with Xcode, and when I hit compile and run... all I get is a black screen, and then my error message that I added in
Code:
//Load the bitmap into a temporary surface, and check for success
temp = SDL_LoadBMP("image.bmp");
if (temp == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}I get
libro has exited with status 1.
[Session started at 2007-01-17 19:15:51 -0300.]
Unable to load bitmap: Couldn't open image.bmp
( all of this in Xcode... I don't know what is wrong... it must be something really stupid I think... I took the image.bmp to the project directory )
, if anyone can help me , it would be great!I really want to get into this,

#########EDIT#######
Guys I managed to load the image specifying the whole path like this
Code:
//Load the bitmap into a temporary surface, and check for success
temp = SDL_LoadBMP("/Volumes/MacHD/Users/USER/progra/SDL/libro/image.bmp");
if (temp == NULL) {
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}Is there an easier way of doing this instead of always specifying the whole path ??
Thanks!!!
place the image next to the built application.
Somewhere like proga/SDL/libro/build/Debug, from memory. Take a look and find the actual application.
Somewhere like proga/SDL/libro/build/Debug, from memory. Take a look and find the actual application.
O_o. All that code just to place an image on the screen? Crazy... I will be in there soon enough, though....
leRiCl Wrote:O_o. All that code just to place an image on the screen? Crazy... I will be in there soon enough, though....
You should see how much code it takes to set up an OpenGL context in Cocoa, load a PNG with libpng, and draw it from a Lua script. SDL is cake.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| How can I load a PNG without premultiplied alpha? | Prime | 6 | 5,514 |
Feb 15, 2005 08:52 PM Last Post: arekkusu |
|
| need help getting quicktime to load textures | xDexx | 8 | 3,545 |
May 7, 2003 03:57 PM Last Post: xDexx |
|
| Help deciding how to load textures? | Mars_999 | 1 | 1,926 |
Feb 20, 2003 10:09 PM Last Post: henryj |
|
| Where can I get a library to load 3D Models? | Mars_999 | 4 | 3,701 |
Aug 25, 2002 06:05 AM Last Post: ggadwa |
|

