Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sdl_graphics.h"
- #include "constants.h"
- SDL_Graphics::SDL_Graphics(int windowWidth, int windowHeight, int bgR, int bgG, int bgB)
- {
- SDL_Init(SDL_INIT_VIDEO);
- TTF_Init();
- screen = SDL_SetVideoMode( windowWidth, windowHeight, SCREEN_BPP, SDL_SWSURFACE );
- SDL_WM_SetCaption( "Dan's 'Conway's Game Of Life' Clone", NULL );
- setBackgroundColor(bgR, bgG, bgB);
- greensquare = loadBitmap("greensquare.bmp");
- redsquare = loadBitmap("redsquare.bmp");
- }
- SDL_Graphics::~SDL_Graphics()
- {
- TTF_Quit();
- SDL_Quit();
- }
- SDL_Surface* SDL_Graphics::loadBitmap(const char* imageFileName)
- {
- SDL_Surface* bitmap = SDL_LoadBMP(imageFileName);
- return bitmap;
- }
- void SDL_Graphics::clearScreen()
- {
- //fill screen with solid color
- SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, backgroundColorRed, backgroundColorGreen, backgroundColorBlue));
- }
- void SDL_Graphics::updateScreen()
- {
- SDL_Flip(screen);
- }
- void SDL_Graphics::drawSprite(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip)
- {
- //Holds offsets
- SDL_Rect offset;
- //Get offsets
- offset.x = x;
- offset.y = y;
- SDL_BlitSurface(source, clip, destination, &offset);
- }
- void SDL_Graphics::setBackgroundColor(int r, int g, int b)
- {
- backgroundColorRed = r;
- backgroundColorGreen = g;
- backgroundColorBlue = b;
- }
- SDL_Surface* SDL_Graphics::getShapeSurfaceGreenSquare()
- {
- return greensquare;
- }
- SDL_Surface* SDL_Graphics::getShapeSurfaceRedSquare()
- {
- return redsquare;
- }
- SDL_Surface* SDL_Graphics::getShapeSurfaceScreen()
- {
- return screen;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement