-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextureLoader.cpp
executable file
·63 lines (51 loc) · 1.22 KB
/
textureLoader.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
#include "headers/textureLoader.h"
TextureLoader* TextureLoader::_instance = NULL;
SDL_Texture* TextureLoader::LoadTexture(std::string path)
{
//The final texture
SDL_Texture* newTexture = NULL;
//Load image at specified path
SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
if( loadedSurface == NULL )
{
printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
}
else
{
//Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface(mWindow->GetRenderer(), loadedSurface);
if( newTexture == NULL )
{
printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
}
//Get rid of old loaded surface
SDL_FreeSurface( loadedSurface );
}
return newTexture;
}
TextureLoader* TextureLoader::Instance()
{
if(_instance == NULL)
{
_instance = new TextureLoader();
}
return _instance;
}
void TextureLoader::SetWindow(Window* window)
{
mWindow = window;
}
Window* TextureLoader::GetWindow()
{
return mWindow;
}
TextureLoader::TextureLoader()
{
}
TextureLoader::~TextureLoader()
{
delete _instance;
delete mWindow;
_instance = NULL;
mWindow = NULL;
}