/
renderer.hpp
69 lines (51 loc) · 1.5 KB
/
renderer.hpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef RENDERER_HPP
#define RENDERER_HPP
//#include <SDL.h>
//#include <SDL_image.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "window.hpp"
#include "texture.hpp"
namespace SDLXX {
class Renderer{
public:
SDL_Renderer *ren = nullptr;
Renderer(SDLXX::Window &window,int index, Uint32 flags){
ren = SDL_CreateRenderer(window.get(),index,flags);
}
~Renderer(){
SDL_DestroyRenderer(ren);
}
SDL_Renderer* get(){
return this->ren;
}
void clear(){
SDL_RenderClear(this->ren);
}
void copy(SDLXX::Texture &tex,SDL_Rect *src,SDL_Rect *dst){
SDL_RenderCopy(this->ren,tex.get(),src,dst);
}
void copyRotate(SDLXX::Texture &tex,
const SDL_Rect* srcrect,
const SDL_Rect* dstrect,
const double angle,
const SDL_Point *center,
const SDL_RendererFlip flip ){
SDL_RenderCopyEx(this->ren,tex.get(),srcrect,dstrect,angle,center,flip);
}
SDLXX::Texture createTexture(const std::string &file){
//auto *surface = SDL_LoadBMP(file.c_str());
auto *surface = IMG_Load(file.c_str());
SDLXX::Texture tex;
tex = SDL_CreateTextureFromSurface(this->ren, surface);
SDL_FreeSurface(surface);
return tex;
}
void present(){
SDL_RenderPresent(this->ren);
}
// SDLXX::Texture loadTexture(const std::string &file){
// }
};
}//namepsace
#endif // RENDERER_HPP