//SDL_Surface Wrapper Class
class Surface
{
private:
SDL_Surface* surface;
public:
//Default Constructor
Surface()
{
surface = NULL;
}
//Loading Constructor
Surface(const char* fileName)
{
LoadBitmap(fileName);
}
//SDL Surface Constructor
Surface(SDL_Surface* newSurface)
{
surface = newSurface;
}
//Return Surface
SDL_Surface* GetSurface()
{
return surface;
}
//Get Surface Width
int GetWidth()
{
return surface->w;
}
//Get Surface Height
int GetHeight()
{
return surface->h;
}
//Get Format of Surface
SDL_PixelFormat* GetFormat()
{
return surface->format;
}
//Get Scanline Length of Surface
Uint16 GetPitch()
{
return surface->pitch;
}
//Get Clipping rectangle of Surface
SDL_Rect GetClip()
{
return surface->clip_rect;
}
//Get Surface Flags
Uint32 GetFlags()
{
return surface->flags;
}
//Image Loading Method
void LoadBitmap(const char* fileName)
{
//Return an optimized version of a loaded bitmap image
surface = SDL_DisplayFormat(SDL_LoadBMP(fileName));
}
//Blit a surface to this surface
void BlitTo(Surface blitSurface, Point point)
{
//Create Rectangle For Coordinates
SDL_Rect destination;
//Give Rectangle Coordinates
destination.x = point.GetX();
destination.y = point.GetY();
//Blit Image to Buffer
SDL_BlitSurface(surface, NULL, blitSurface.GetSurface(), &destination);
}
//Fill Surface With Color
void Fill(int r, int g, int b)
{
SDL_FillRect(surface, 0, SDL_MapRGB(GetFormat(),r,g,b));
}
//Flip Image To Screen
void Flip()
{
SDL_Flip(surface);
}
//Destructor
~Surface()
{
SDL_FreeSurface(surface);
}
};
Surface mySurface("image.bmp"); //Load the surface
Sprite mySprite(mySurface); //Create a sprite with mySurface as the surface
mySurface.BlitTo(screen);