-
Notifications
You must be signed in to change notification settings - Fork 0
/
Texture.cpp
83 lines (61 loc) · 1.06 KB
/
Texture.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Texture.h"
Texture::Texture()
{
texture = nullptr;
width = 0;
height = 0;
}
Texture::~Texture()
{
Free();
}
bool Texture::LoadFromFile(SDL_Renderer* gRenderer, const std::string path)
{
Free();
//final texture
SDL_Texture* finalTexture = nullptr;
//load the file
finalTexture = IMG_LoadTexture(gRenderer, path.c_str());
if (finalTexture == nullptr)
{
printf("failed to load image. SDL Error: %s\n", SDL_GetError());
}
else
{
int w, h;
if (SDL_QueryTexture(finalTexture, NULL, NULL, &w, &h) != 0)
{
printf("failed to query texture. you're not gonna know shit about it.");
}
else
{
width = w;
height = h;
}
}
//sets our suface turned texture to our member vairable texture.
texture = finalTexture;
return texture != nullptr;
}
void Texture::Free()
{
if (texture != nullptr)
{
SDL_DestroyTexture(texture);
texture = nullptr;
width = 0;
height = 0;
}
}
float Texture::GetWidth()
{
return width;
}
float Texture::GetHeight()
{
return height;
}
SDL_Texture* Texture::GetTexture()
{
return texture;
}