-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLTexture.cpp
More file actions
executable file
·76 lines (60 loc) · 1.38 KB
/
Copy pathLTexture.cpp
File metadata and controls
executable file
·76 lines (60 loc) · 1.38 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
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
#include "LTexture.h"
LTexture::LTexture()
{
free();
}
LTexture::~LTexture()
{
free();
}
void LTexture::free()
{
if(mTexture != NULL)
{
SDL_DestroyTexture(mTexture);
mTexture = NULL;
}
mWidth = 0;
mHeight = 0;
}
bool LTexture::loadFromFile(std::string path)
{
bool success = true;
SDL_Texture* newTexture = NULL;
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if(loadedSurface == NULL)
{
success = false;
}
else
{
SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 255, 255));
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
if(newTexture != NULL)
{
mTexture = newTexture;
mWidth = loadedSurface -> w;
mHeight = loadedSurface -> h;
}
}
SDL_FreeSurface(loadedSurface);
return success;
}
void LTexture::render(int x, int y, SDL_Rect* clip, SDL_RendererFlip flip)
{
SDL_Rect renderQuad = {x, y, mWidth, mHeight};
if(clip != NULL)
{
renderQuad.w = clip -> w;
renderQuad.h = clip -> h;
}
SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, 0.0, NULL, flip);
}
int LTexture::getWidth()
{
return mWidth;
}
int LTexture::getHeight()
{
return mHeight;
}