Suby

sdl_graphics.cpp

May 25th, 2012
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include "sdl_graphics.h"
  2. #include "constants.h"
  3.  
  4. SDL_Graphics::SDL_Graphics(int windowWidth, int windowHeight, int bgR, int bgG, int bgB)
  5. {
  6. SDL_Init(SDL_INIT_VIDEO);
  7.  
  8. TTF_Init();
  9.  
  10. screen = SDL_SetVideoMode( windowWidth, windowHeight, SCREEN_BPP, SDL_SWSURFACE );
  11.  
  12. SDL_WM_SetCaption( "Dan's 'Conway's Game Of Life' Clone", NULL );
  13.  
  14. setBackgroundColor(bgR, bgG, bgB);
  15.  
  16. greensquare = loadBitmap("greensquare.bmp");
  17.  
  18. redsquare = loadBitmap("redsquare.bmp");
  19. }
  20.  
  21. SDL_Graphics::~SDL_Graphics()
  22. {
  23. TTF_Quit();
  24. SDL_Quit();
  25. }
  26.  
  27. SDL_Surface* SDL_Graphics::loadBitmap(const char* imageFileName)
  28. {
  29. SDL_Surface* bitmap = SDL_LoadBMP(imageFileName);
  30. return bitmap;
  31. }
  32.  
  33. void SDL_Graphics::clearScreen()
  34. {
  35. //fill screen with solid color
  36. SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, backgroundColorRed, backgroundColorGreen, backgroundColorBlue));
  37. }
  38.  
  39. void SDL_Graphics::updateScreen()
  40. {
  41. SDL_Flip(screen);
  42. }
  43.  
  44. void SDL_Graphics::drawSprite(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip)
  45. {
  46. //Holds offsets
  47. SDL_Rect offset;
  48.  
  49. //Get offsets
  50. offset.x = x;
  51. offset.y = y;
  52. SDL_BlitSurface(source, clip, destination, &offset);
  53. }
  54.  
  55. void SDL_Graphics::setBackgroundColor(int r, int g, int b)
  56. {
  57. backgroundColorRed = r;
  58. backgroundColorGreen = g;
  59. backgroundColorBlue = b;
  60. }
  61.  
  62. SDL_Surface* SDL_Graphics::getShapeSurfaceGreenSquare()
  63. {
  64. return greensquare;
  65. }
  66.  
  67. SDL_Surface* SDL_Graphics::getShapeSurfaceRedSquare()
  68. {
  69. return redsquare;
  70. }
  71.  
  72.  
  73. SDL_Surface* SDL_Graphics::getShapeSurfaceScreen()
  74. {
  75. return screen;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment