-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcTexture.cpp
More file actions
143 lines (133 loc) · 3.84 KB
/
cTexture.cpp
File metadata and controls
143 lines (133 loc) · 3.84 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
=================
cTexture.cpp
- CPP file for class definition - IMPLEMENTATION
- CPP file for the cTexture class
=================
*/
#include "cTexture.h"
using namespace std;
/*
=================
- Data constructor initializes the OpenGL Texture ID object
- Is always called, thus ensures all OpenGL Texture ID objects are in a consistent state.
=================
*/
cTexture::cTexture()
{
cTexture::sdlTextureID = NULL;
}
/*
=================
- Data constructor initializes the OpenGL Texture ID object
- Is always called, thus ensures all OpenGL Texture ID objects are in a consistent state.
* @param theFilename The image file to load
=================
*/
cTexture::cTexture(LPCSTR theFilename, SDL_Renderer *theRenderer)
{
cTexture::loadTexture(theFilename, theRenderer);
}
/*
=================
- Destructor.
=================
*/
cTexture::~cTexture()
{
SDL_DestroyTexture(sdlTextureID);
}
/*
=================
- create the texture for use.
=================
*/
bool cTexture::loadTexture(LPCSTR theFilename, SDL_Renderer *theRenderer) // create the texture for use.
{
// Call SDL_Image IMG_LoadTexture to create the desired texture
sdlTextureID = IMG_LoadTexture(theRenderer, theFilename);
// Check the Texture has been created from the surface
if (sdlTextureID != 0)
{
cout << "Texture '" << theFilename << "' successfully loaded." << endl;
SDL_QueryTexture(sdlTextureID, NULL, NULL, &textureWidth, &textureHeight); // determine the width an height of the texture
return true;
}
else
{
cout << "Texture '" << theFilename << "' could not be loaded!!" << endl;
cout << SDL_GetError() << endl;
}
return false;
}
bool cTexture::loadTexture(SDL_Texture* theTexture) // create the texture for use.
{
// Call SDL_Image IMG_LoadTexture to create the desired texture
sdlTextureID = theTexture;
// Check the Texture has been created from the surface
if (sdlTextureID != 0)
{
cout << "Texture successfully loaded." << endl;
SDL_QueryTexture(sdlTextureID, NULL, NULL, &textureWidth, &textureHeight); // determine the width an height of the texture
return true;
}
else
{
cout << "Texture could not be loaded!!" << endl;
cout << SDL_GetError() << endl;
}
return false;
}
/*
=================
- return the texture.
=================
*/
SDL_Texture* cTexture::getTexture() // return the texture.
{
return cTexture::sdlTextureID;
}
/*
=================
- Return width of texture.
=================
*/
int cTexture::getTWidth() // Return width of texture;
{
return textureWidth;
}
/*
=================
- Return height of texture.
=================
*/
int cTexture::getTHeight() // Return height of texture;
{
return textureHeight;
}
/*
=================
- Render the texture.
=================
*/
void cTexture::renderTexture(SDL_Renderer* theRenderer, SDL_Texture* ptheTexture, SDL_Rect* theSourceRect, SDL_Rect* theDestRect, FPoint theScaling)
{
//SDL_RenderSetScale(theRenderer, theScaling.X, theScaling.Y);
SDL_RenderCopy(theRenderer, ptheTexture, theSourceRect, theDestRect);
}
void cTexture::renderTexture(SDL_Renderer* theRenderer, SDL_Texture* ptheTexture, SDL_Rect* theSourceRect, SDL_Rect* theDestRect, double rotAngle, SDL_Point* spriteCentre, FPoint theScaling)
{
//SDL_RenderSetScale(theRenderer, theScaling.X, theScaling.Y);
SDL_RenderCopyEx(theRenderer, ptheTexture, theSourceRect, theDestRect, rotAngle, spriteCentre, SDL_FLIP_NONE);
}
/*
==========================================================================
Render the text using the desired font
==========================================================================
*/
SDL_Rect cTexture::getTextureRect()
{
SDL_Rect txtRect = { 0, 0, 0, 0 };
SDL_QueryTexture(this->sdlTextureID, NULL, NULL, &txtRect.w, &txtRect.h);
return txtRect;
}