summaryrefslogtreecommitdiff
path: root/src/renderer.cpp
blob: 2f90a8d042025ba5f7a6ad55dd2de0ddaf0a546c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "renderer.h"

Renderer::Renderer(){
    renderer_ = nullptr;
}

Renderer::~Renderer(){
    SDL_DestroyRenderer(renderer_);
}

void Renderer::init( SDL_Window* win ) {
    if (renderer_){
        SDL_DestroyRenderer(renderer_);
    }
    renderer_ = SDL_CreateRenderer( win, -1, SDL_RENDERER_ACCELERATED);
    if (renderer_ == NULL){
        printf("Unable to create rendering context: %s", SDL_GetError());
    }
}

void Renderer::clear(){
    SDL_RenderClear(renderer_);
}
void Renderer::update(){
    SDL_RenderPresent(renderer_);
}

SDL_Renderer * Renderer::renderer(){
    return renderer_;
}

void Renderer::setScale(int scaleX, int scaleY){
    if( SDL_RenderSetScale(renderer_, scaleX, scaleY) < 0){
        printf("Unable to set scale in renderer: %s", SDL_GetError());
    }
}