I am trying to cut big PNG image (with alpha chanel) to pieces, like that:---------------------
SDL_Surface *CutFromBigImage(SDL_Surface *src, …) {
SDL_Rect rect;
SDL_Surface *dst;
rect.* = …; // fill it with coordinates
dst = SDL_CreateRGBSurface(src->flags, rect.w, rect.h,
src->format->BitsPerPixel,
src->format->Rmask, src->format->Gmask,
src->format->Bmask, src->format->Amask);
SDL_BlitSurface(src, &rect, dst, NULL);
return dst;
}
And it doesn’t work. I recieve an empty or complitely transparent small image.
If I replace SDL_BlitSurface() with manual loop like:
int x, y;
Uint8 r,g,b,a;
for(x=0; x<rect.w; x++) for(y=0; y<rect.h; y++) {
getPixel(src, x+rect.x, y+rect.y, &r, &g, &b, &a);
setPixel(dst, x, y, r, g, b, a);
}
I get a nice small sprite. So the question is what do I do wrong with
SDL_BlitSurface?