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;
}