forgive the newbie question, but i’m working my way through the intro
code in the SDL DOC project, and have come across the error
"SDL_UpperBlit: Passed mismatched rectangles" when trying to blit a
bitmap onto the screen. The code works fine when the bitmap is the exact
same dimensions as the screen surface, but if the bitmap is smaller then
i get the error. I am using SDL 1.2.0 and running this in X under linux
(kernel 2.2.16-22).
looking at the image and screen surface clip_rects in gdb with a
breakpiont at the SDL_BlitSurface call, they both have h=0, which
mystifies me. I also tried using SDL_SetClipRect( …, NULL ) to set the
surface’s clip_rects to the whole surface, but the linker couldn’t find
SDL_SetClipRect (which also mystifies me - how could compile without
complaining and it link to all the other SDL functions but just not find
this one?)
here is source …
#include <SDL/SDL.h>
#include <stdio.h>
int main(int argc, char **argv) {
SDL_Surface *screen, *image;
/* init SDL library */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf( stderr, “Couldn’t initialize SDL: %s\n”, SDL_GetError());
exit(-1);
}
/* clean up at exit */
atexit(SDL_Quit);
/* init display to 640x480 8bpp palettized mode w/ software surface */
screen = SDL_SetVideoMode(800, 600, 8, SDL_SWSURFACE|SDL_ANYFORMAT);
if( screen == NULL ) {
fprintf( stderr, “Couldn’t set 640x480x8 video mode: %s\n”,
SDL_GetError());
exit(-1);
}
printf(“Set 640x480 at %d bits-per-pixel mode\n”,
screen->format->BitsPerPixel);
/* load in a BMP image */
image = SDL_LoadBMP(argv[1]);
if(image==NULL) {
fprintf(stderr, “Couldn’t load %s: %s\n”, argv[1], SDL_GetError());
return;
}
/* if this is a palettized screen mode, use the image’s color palette */
if(image->format->palette && screen->format->palette) {
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}
/* blit onto the screen surface */
if(SDL_BlitSurface(image, NULL, screen, NULL) < 0 )
fprintf(stderr, “BlitSurface error: %s\n”, SDL_GetError());
SDL_UpdateRect(screen, 0,0, image->w, image->h);
/* free the allocated BMP surface */
SDL_FreeSurface(image);
getc(stdin);
exit(0);
}