Newbie: SDL with Cocoa -- cannot load the image

Hello, I just moved to Mac OS X environment (version 10.1.5, 512MB) and
tried to use SDL.
When I compile the code below, the error message “Unable to load
bitmap.” is shown.
(I added the image file from the menu “Project” – “add files”.) How can
I solve this?

Sincerely,
saito hiroyuki--------------------------------------------------
/* Simple blitting with SDL. */

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
SDL_Surface *screen;
SDL_Surface *image;
SDL_Rect src, dest;

/* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
	printf("Couldn't initialize SDL: %s\n",
		SDL_GetError());
	return 1;
}

     /* Make sure SDL_Quit gets called when the program exits. */
     atexit(SDL_Quit);

/* Set 256x256 hicolor (16-bit) video mode */
screen = SDL_SetVideoMode(256, 256, 16, 0);
     if (screen == NULL) {
	printf("Couldn't set 256x256 video mode: %s\n",
                     SDL_GetError());
	return 1;
}

     /* Load the bitmap file. SDL_LoadBMP returns a point to a
        new surface containing the loaded image. */
     image = SDL_LoadBMP("test-image.bmp");
     if (image == NULL) {
         printf("Unable to load bitmap.\n");
         return 1;
     }

     /* The SDL blitting function needs to know how much data to 

copy. */
src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;

     dest.x = 0;
     dest.y = 0;
     dest.w = image->w;
     dest.h = image->h;

     /* Draw the bitmap to the screen. */
     SDL_BlitSurface(image, &src, screen, &dest);

     /* Ask SDL to update the entire screen. */
     SDL_UpdateRect(screen, 0, 0, 0, 0);

     /* Pause for a few seconds as the viewer gasps in awe. */
     SDL_Delay(3000);

     /* Free the memory that was allocated to the bitmap. */
     SDL_FreeSurface(image);

return 0;

}

Hello, I just moved to Mac OS X environment (version 10.1.5, 512MB) and
tried to use SDL.
When I compile the code below, the error message “Unable to load
bitmap.” is shown.
(I added the image file from the menu “Project” – “add files”.) How can
I solve this?

Ok i don;t know what development envinronment do you use. But i suppose
that add files only says that this file belongs to your project but it
doesn’t copy it into current directory.

[…]

     image = SDL_LoadBMP("test-image.bmp");

if you do this you have to have test-image.bmp in curent dir.
[…]
Bye

Hello, I just moved to Mac OS X environment (version 10.1.5, 512MB)
and tried to use SDL.
When I compile the code below, the error message “Unable to load
bitmap.” is shown.
(I added the image file from the menu “Project” – “add files”.) How
can I solve this?

The image file needs to be in the same directory as the .app bundle.

-DOn Saturday, October 19, 2002, at 12:10 PM, saito hiroyuki wrote:

Great thanks.

With the instruction from Krata and Darrel (place/copy the image file
into the same folder as the application),
the code properly works!! Thanks again!!

Peace,
saito hiroyuki> From: Darrell Walisser

Date: Sun Oct 20, 2002 04:03:52 AM Asia/Tokyo
To: sdl at libsdl.org
Subject: Re: [SDL] Newbie: SDL with Cocoa – cannot load the image
Reply-To: sdl at libsdl.org

On Saturday, October 19, 2002, at 12:10 PM, saito hiroyuki wrote:

Hello, I just moved to Mac OS X environment (version 10.1.5, 512MB)
and tried to use SDL.
When I compile the code below, the error message “Unable to load
bitmap.” is shown.
(I added the image file from the menu “Project” – “add files”.) How
can I solve this?

The image file needs to be in the same directory as the .app bundle.

-D


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl