This should work for you. Note that “screen” is your sdl screen as defined by SDL_SetVideoMode.
void drawClippedImage(SDL_Surface *original, int srcX, int srcY, int destX, int destY, int width, int height)
SDL_Rect src, dest;
// Set the source x, y, width and height src.x = srcX; src.y = srcY; src.w = width; src.h = height; // Set the destination x, y, width and height dest.x = destX; dest.y = destY; dest.w = width; dest.h = height; // Copy the portion of the original image to the screen SDL_BlitSurface(original, &src, screen, &dest);
So if you wanted to copy from 50, 0 and blit it to 200, 400 and the width is 32 and the height is 64, you would call
drawClippedImage(original, 50, 50, 200, 400, 32, 64);