Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Graphics.cpp
- * Holds info for dealing with game's graphics
- *
- *
- */
- #include <SDL2/SDL.h>
- #include <iostream>
- #include "Graphics.h"
- #include "functions.h"
- Graphics::Graphics() {
- _windowTitle= "Tic tac toe";
- _windowWidth= 640;
- _windowHeight= 480;
- _window= SDL_CreateWindow(_windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _windowWidth, _windowHeight, SDL_WINDOW_SHOWN);
- if(_window == 0){
- printError("SDL_CreateWindow");
- SDL_Quit();
- }
- _renderingDriverIndex= -1; // get the index of the first graphics driver available(?)
- _rendererFlags= SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC; // use GPU, VSYNC
- _renderer= SDL_CreateRenderer(_window, _renderingDriverIndex, _rendererFlags);
- if(_renderer == NULL){
- printError("SDL_CreateRenderer");
- SDL_Quit();
- }
- }
- Graphics::~Graphics() {
- SDL_DestroyWindow(_window);
- SDL_DestroyRenderer(_renderer);
- }
- void Graphics::changeWindowSize(int width, int height){
- SDL_SetWindowSize(_window, width, height);
- }
- SDL_Renderer* Graphics::getRenderer(){
- return _renderer;
- }
- Layer::Layer(SDL_Renderer* renderer, int& width, int& height) {
- _texture= SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height);
- }
- Layer::~Layer(){
- SDL_DestroyTexture(_texture);
- }
- SDL_Texture* Layer::getTexture(){
- return _texture;
- }
Add Comment
Please, Sign In to add comment