Start New Discussion within our Software Development Community

Here are some functions I made for SDL abstraction:

SDL_Surface* getImage(string filename, int r=255, int g=0, int b=198) 
    SDL_Surface* loadedImage=0;
    SDL_Surface* optimizedImage=0;
    optimizedImage = SDL_DisplayFormat(loadedImage);
    Uint32 colorkey=SDL_MapRGB(optimizedImage->format, r, g, b);
    SDL_SetColorKey(optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey);

    return optimizedImage;

void drawSurface(int x, int y, SDL_Surface* source, SDL_Surface* destination, int cX=0, int cY=0, int cW=0, int cH=0)
    SDL_Rect offset={x, y};
    SDL_Rect clip={cX, cY, cW, cH};
    SDL_Rect* pClip=&clip;
    if(!cX && !cY && !cW && !cH)
	SDL_BlitSurface(source, 0, destination, &offset);
	SDL_BlitSurface(source, pClip, destination, &offset);

void drawText(int x, int y, string text, SDL_Surface* destination, TTF_Font* font,  int fR=255, int fG=255, int fB=255, int bR=0, int bG=0, int bB=0)
     SDL_Color foregroundColor={fR, fG, fB};
     SDL_Color backgroundColor={bR, bG, bB};

     SDL_Surface* textSurface=TTF_RenderText_Shaded(font, text.c_str(), foregroundColor, backgroundColor);

     apply_surface(x, y,  textSurface, destination);

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.