-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrappers.cpp
More file actions
48 lines (39 loc) · 1.28 KB
/
Wrappers.cpp
File metadata and controls
48 lines (39 loc) · 1.28 KB
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
#include <iostream>
#include "SDL_ttf.h"
#include "SDL_image.h"
#include "Wrappers.hpp"
#include "Game.hpp"
TextureWrapper::TextureWrapper(const char* imagePath)
{
std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)> tempSurface(IMG_Load(imagePath), SDL_FreeSurface);
initSurfaceInfo(std::move(tempSurface));
}
//#pragma optimize("", off)
TextureWrapper::TextureWrapper(SDL_Color color, const char symbol)
{
// init temp tempFont with auto-cleanup
//std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)> tempFont(TTF_OpenFont(fontPath, fontSize), TTF_CloseFont);
// init temp surface with auto-cleanup
std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)> tempSurface(TTF_RenderText_Solid(Game::defaultFont, &symbol, color), SDL_FreeSurface);
initSurfaceInfo(std::move(tempSurface));
}
// turn off optimization for this function
void TextureWrapper::initSurfaceInfo(std::unique_ptr<SDL_Surface, decltype(&SDL_FreeSurface)> surface)
{
texture.reset(SDL_CreateTextureFromSurface(Game::renderer, surface.get()));
width = surface->w;
height = surface->h;
}
//#pragma optimize("", on)
SDL_Texture* TextureWrapper::getTextureRaw() const
{
return texture.get();
}
const int TextureWrapper::getWidth() const
{
return width;
}
const int TextureWrapper::getHeight() const
{
return height;
}