-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextureManager.cpp
73 lines (64 loc) · 2.27 KB
/
textureManager.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
// Programming 2D Games
// Copyright (c) 2011 by:
// Charles Kelly
// textureManager.cpp v1.0
// A TextureManager object loads and maintains one texture file.
// Create a TextureManager object for each texture file in the game.
#include "textureManager.h"
//=============================================================================
// default constructor
//=============================================================================
TextureManager::TextureManager()
{
texture = NULL;
width = 0;
height = 0;
file = NULL;
graphics = NULL;
initialized = false; // set true when successfully initialized
}
//=============================================================================
// destructor
//=============================================================================
TextureManager::~TextureManager()
{
SAFE_RELEASE(texture);
}
//=============================================================================
// Loads the texture file from disk.
// Post: returns true if successful, false if failed
//=============================================================================
bool TextureManager::initialize(Graphics *g, const char *f)
{
try{
graphics = g; // the graphics object
file = f; // the texture file
hr = graphics->loadTexture(file, TRANSCOLOR, width, height, texture);
if (FAILED(hr))
{
SAFE_RELEASE(texture);
return false;
}
}
catch(...) {return false;}
initialized = true; // set true when successfully initialized
return true;
}
//=============================================================================
// called when graphics device is lost
//=============================================================================
void TextureManager::onLostDevice()
{
if (!initialized)
return;
SAFE_RELEASE(texture);
}
//=============================================================================
// called when graphics device is reset
//=============================================================================
void TextureManager::onResetDevice()
{
if (!initialized)
return;
graphics->loadTexture(file, TRANSCOLOR, width, height, texture);
}