SDL_Surface* getImage(string filename, int r=255, int g=0, int b=198) 
{
    SDL_Surface* loadedImage=0;
    SDL_Surface* optimizedImage=0;
    
    loadedImage=IMG_Load(filename.c_str());
    optimizedImage = SDL_DisplayFormat(loadedImage);
    SDL_FreeSurface(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);
    else
	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);

     SDL_FreeSurface(textSurface);
}
1
Contributor
1
Reply
2
Views
10 Years
Discussion Span
Last Post by Sturm
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.