Guest User

Untitled

a guest
Feb 8th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. /*
  2.  * Graphics.cpp
  3.  * Holds info for dealing with game's graphics
  4.  *
  5.  *
  6.  */
  7.  
  8. #include <SDL2/SDL.h>
  9. #include <iostream>
  10.  
  11. #include "Graphics.h"
  12. #include "functions.h"
  13.  
  14. Graphics::Graphics() {
  15.     _windowTitle=   "Tic tac toe";
  16.     _windowWidth=   640;
  17.     _windowHeight=  480;
  18.     _window=        SDL_CreateWindow(_windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _windowWidth, _windowHeight, SDL_WINDOW_SHOWN);
  19.     if(_window == 0){
  20.         printError("SDL_CreateWindow");
  21.         SDL_Quit();
  22.     }
  23.  
  24.     _renderingDriverIndex=  -1;                                                     // get the index of the first graphics driver available(?)
  25.     _rendererFlags=         SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;   // use GPU, VSYNC
  26.     _renderer=              SDL_CreateRenderer(_window, _renderingDriverIndex, _rendererFlags);
  27.     if(_renderer == NULL){
  28.         printError("SDL_CreateRenderer");
  29.         SDL_Quit();
  30.     }
  31. }
  32.  
  33. Graphics::~Graphics() {
  34.     SDL_DestroyWindow(_window);
  35.     SDL_DestroyRenderer(_renderer);
  36. }
  37.  
  38. void Graphics::changeWindowSize(int width, int height){
  39.     SDL_SetWindowSize(_window, width, height);
  40. }
  41.  
  42. SDL_Renderer* Graphics::getRenderer(){
  43.     return _renderer;
  44. }
  45.  
  46.  
  47. Layer::Layer(SDL_Renderer* renderer, int& width, int& height) {
  48.     _texture=       SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
  49. }
  50.  
  51. Layer::~Layer(){
  52.     SDL_DestroyTexture(_texture);
  53. }
  54.  
  55. SDL_Texture* Layer::getTexture(){
  56.     return _texture;
  57. }
Add Comment
Please, Sign In to add comment