-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextureManager.cpp
More file actions
204 lines (166 loc) · 12.9 KB
/
TextureManager.cpp
File metadata and controls
204 lines (166 loc) · 12.9 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "TextureManager.h"
#include "GL\freeglut.h"
#include <fstream>
#include <string>
/// <summary>
/// Loads all the textures used in the program into memory.
/// </summary>
void TextureManager::LoadAllTextures()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // (Actually, this one is the default)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
LoadTexture((char*)"Textures\\Ship front.bmp", this->ShipFrontTextureID);
LoadTexture((char*)"Textures\\Ship middle.bmp", this->ShipMiddleTextureID);
LoadTexture((char*)"Textures\\Ship Back.bmp", this->ShipBackTextureID);
LoadTexture((char*)"Textures\\Ship front Deployable.bmp", this->ShipFrontDeployableTextureID);
LoadTexture((char*)"Textures\\Ship middle Deployable.bmp", this->ShipMiddleDeployableTextureID);
LoadTexture((char*)"Textures\\Ship Back Deployable.bmp", this->ShipBackDeployableTextureID);
LoadTexture((char*)"Textures\\Ship front Undeployable.bmp", this->ShipFrontUndeployableTextureID);
LoadTexture((char*)"Textures\\Ship middle Undeployable.bmp", this->ShipMiddleUndeployableTextureID);
LoadTexture((char*)"Textures\\Ship Back Undeployable.bmp", this->ShipBackUndeployableTextureID);
LoadTexture((char*)"Textures\\Ship front Afire.bmp", this->ShipFrontAfireTextureID);
LoadTexture((char*)"Textures\\Ship middle Afire.bmp", this->ShipMiddleAfireTextureID);
LoadTexture((char*)"Textures\\Ship Back Afire.bmp", this->ShipBackAfireTextureID);
LoadTexture((char*)"Textures\\Ship Afire.bmp", this->ShipAfireTextureID);
LoadTexture((char*)"Textures\\Ship Afire aim.bmp", this->ShipAfireAimTextureID);
LoadTexture((char*)"Textures\\Ship front Cracked.bmp", this->ShipFrontCrackedTextureID);
LoadTexture((char*)"Textures\\Ship middle Cracked.bmp", this->ShipMiddleCrackedTextureID);
LoadTexture((char*)"Textures\\Ship Back Cracked.bmp", this->ShipBackCrackedTextureID);
LoadTexture((char*)"Textures\\Ship front Cracked Aim.bmp", this->ShipFrontCrackedAimTextureID);
LoadTexture((char*)"Textures\\Ship middle Cracked Aim.bmp", this->ShipMiddleCrackedAimTextureID);
LoadTexture((char*)"Textures\\Ship Back Cracked Aim.bmp", this->ShipBackCrackedAimTextureID);
LoadTexture((char*)"Textures\\Single Ship.bmp", this->SingleShipTextureID);
LoadTexture((char*)"Textures\\Single Ship Aim.bmp", this->SingleShipAimTextureID);
LoadTexture((char*)"Textures\\Single Ship Cracked.bmp", this->SingleShipCrackedTextureID);
LoadTexture((char*)"Textures\\Single Ship Cracked Aim.bmp", this->SingleShipCrackedAimTextureID);
LoadTexture((char*)"Textures\\Single Ship Deployable.bmp", this->SingleShipDeployableTextureID);
LoadTexture((char*)"Textures\\Single Ship Undeployable.bmp", this->SingleShipUndeployableTextureID);
LoadTexture((char*)"Textures\\WaterAim.bmp", this->WaterAimTextureID);
LoadTexture((char*)"Textures\\ButtonFieldFire.bmp", this->ButtonFieldFireTextureID);
LoadTexture((char*)"Textures\\ButtonFieldDeploy.bmp", this->ButtonFieldDeployTextureID);
LoadTexture((char*)"Textures\\ButtonFieldNewGame.bmp", this->ButtonFieldNewGameTextureID);
LoadTexture((char*)"Textures\\ButtonFieldPleaseWait.bmp", this->ButtonFieldPleaseWaitTextureID);
LoadTexture((char*)"Textures\\ButtonFieldConnect_AutoManual.bmp", this->ButtonFieldConnect_AutoManualTextureID);
LoadTexture((char*)"Textures\\ButtonFieldConnect_A_Connection.bmp", this->ButtonFieldConnect_A_ConnectionTextureID);
LoadTexture((char*)"Textures\\ButtonFieldConnect_M_ServerClient.bmp", this->ButtonFieldConnect_M_ServerClientTextureID);
LoadTexture((char*)"Textures\\ButtonFieldConnect_M_ClientConnection.bmp", this->ButtonFieldConnect_M_ClientConnectionTextureID);
LoadTexture((char*)"Textures\\ButtonFieldConnect_M_ServerConnection.bmp", this->ButtonFieldConnect_M_ServerConnectionTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldNewGame.bmp", this->ClueFieldNewGameTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldChooseConnType.bmp", this->ClueFieldChooseConnTypeTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldChooseConnSide.bmp", this->ClueFieldChooseConnSideTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldDeploy.bmp", this->ClueFieldDeployingTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldMainGame.bmp", this->ClueFieldMainGameTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldYouWon.bmp", this->ClueFieldYouWonTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldYouLost.bmp", this->ClueFieldYouLostTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldInputIP.bmp", this->ClueFieldInputIPTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldShowIP.bmp", this->ClueFieldShowIPTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldConnSearch.bmp", this->ClueFieldConnSearchTextureID);
LoadTexture((char*)"Textures\\ClueFieldTextures\\ClueFieldDisconnecting.bmp", this->ClueFieldDisconnectingTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Top\\StatusFieldTopPVE.bmp", this->StatusFieldTopPVETextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Top\\StatusFieldTopPVP.bmp", this->StatusFieldTopPVPTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Top\\StatusFieldTopMainMenu.bmp", this->StatusFieldTopMainMenuTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomYourTurn.bmp", this->StatusFieldBottomYourTurnTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomChooseGame.bmp", this->StatusFieldBottomChooseGameTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomDeployShips.bmp", this->StatusFieldBottomDeployShipsTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomOpponentTurn.bmp", this->StatusFieldBottomOpponentTurnTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomInputIP.bmp", this->StatusFieldBottomInputIPTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomSearchingConnection.bmp", this->StatusFieldBottomSearchingConnectionTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomWaitingConnection.bmp", this->StatusFieldBottomWaitingConnectionTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomChooseConnType.bmp", this->StatusFieldBottomChooseConnTypeTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomChooseConnSide.bmp", this->StatusFieldBottomChooseConnSideTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomDisconnect.bmp", this->StatusFieldBottomDisconnectTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomOpponentReady.bmp", this->StatusFieldBottomOpponentReadyTextureID);
LoadTexture((char*)"Textures\\StatusFieldTextures\\Bottom\\StatusFieldBottomWaitingOnOpponent.bmp", this->StatusFieldBottomWaitingOnOpponentTextureID);
LoadTexture((char*)"Textures\\StatisticField.bmp", this->StatisticFieldTextureID);
LoadTexture((char*)"Textures\\sea.bmp", this->WaterTextureID);
LoadTexture((char*)"Textures\\Rocket Missed.bmp", this->MissedTextureID);
LoadTexture((char*)"Textures\\Rocket Missed Aim.bmp", this->MissedAimTextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number0.bmp", this->TimeNumber0TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number1.bmp", this->TimeNumber1TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number2.bmp", this->TimeNumber2TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number3.bmp", this->TimeNumber3TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number4.bmp", this->TimeNumber4TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number5.bmp", this->TimeNumber5TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number6.bmp", this->TimeNumber6TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number7.bmp", this->TimeNumber7TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number8.bmp", this->TimeNumber8TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\Number9.bmp", this->TimeNumber9TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\TimeTextures\\colon.bmp", this->TimeColonTextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber0.bmp", this->AliveDeadNumber0TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber1.bmp", this->AliveDeadNumber1TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber2.bmp", this->AliveDeadNumber2TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber3.bmp", this->AliveDeadNumber3TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber4.bmp", this->AliveDeadNumber4TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber5.bmp", this->AliveDeadNumber5TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber6.bmp", this->AliveDeadNumber6TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber7.bmp", this->AliveDeadNumber7TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber8.bmp", this->AliveDeadNumber8TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber9.bmp", this->AliveDeadNumber9TextureID);
LoadTexture((char*)"Textures\\SymbolTextures\\AliveDeadTextures\\BigNumber10.bmp", this->AliveDeadNumber10TextureID);
LoadTexture((char*)"Textures\\Cannon.bmp", this->CannonTextureID);
LoadTexture((char*)"Textures\\CannonBackround.bmp", this->CannonBackroundTextureID);
LoadTexture((char*)"Textures\\Explosion.bmp", this->ExplosionTextureID);
LoadTexture((char*)"Textures\\Rocket Body.bmp", this->RocketBodyTextureID);
LoadTexture((char*)"Textures\\Rocket top.bmp", this->RocketTopTextureID);
LoadTexture((char*)"Textures\\Rocket Fin Bottom.bmp", this->RocketFinBottomTextureID);
LoadTexture((char*)"Textures\\Rocket Fin Top.bmp", this->RocketFinTopTextureID);
LoadTexture((char*)"Textures\\Sound_On.bmp", this->SoundOnTextureID);
LoadTexture((char*)"Textures\\Sound_Off.bmp", this->SoundOffTextureID);
LoadTexture((char*)"Textures\\Searching Icon.bmp", this->SearchingIconTextureID);
LoadTexture((char*)"Textures\\DisconnectingDots.bmp", this->DisconnectingDotsTextureID);
}
/// <summary>
/// Loads a texture into memory.
/// </summary>
/// <param name="FileName: ">The path of the texture to be loaded.</param>
/// <param name="Texture_ID: ">The ID of the texture to be binded to.</param>
/// <returns>True if successful load, otherwise false.</returns>
bool TextureManager::LoadTexture(char* FileName, GLuint& Texture_ID)
{
BITMAPFILEHEADER* bmpHeader = nullptr; // Header
BITMAPINFOHEADER* bmpInfo = nullptr; // Info
uint8_t* BMPHeaderBuffer = new uint8_t[sizeof(BITMAPFILEHEADER)];
uint8_t* BMPInfoBuffer = new uint8_t[sizeof(BITMAPINFOHEADER)];
std::ifstream file(FileName, std::ios::binary);
if (!file)
{
MessageBox(NULL, L"Failure to open bitmap file.", L"Texture failure", MB_OK);
return false;
}
file.read((char*)BMPHeaderBuffer, sizeof(BITMAPFILEHEADER));
file.read((char*)BMPInfoBuffer, sizeof(BITMAPINFOHEADER));
bmpHeader = (BITMAPFILEHEADER*)BMPHeaderBuffer;
bmpInfo = (BITMAPINFOHEADER*)BMPInfoBuffer;
if (bmpHeader->bfType != 0x4D42)
{
std::string FailureMSG = "File \"";
FailureMSG += FileName;
FailureMSG += "\" isn't a bitmap file\n";
MessageBoxA(NULL, FailureMSG.c_str(), "Texture Failure", MB_OK);
return false;
}
uint8_t* BMPPixelsBuffer = new uint8_t[bmpInfo->biSizeImage];
// Go to where image data starts, then read in image data
file.seekg(bmpHeader->bfOffBits);
file.read((char*)BMPPixelsBuffer, bmpInfo->biSizeImage);
GLuint _width = bmpInfo->biWidth;
GLuint _height = bmpInfo->biHeight;
glGenTextures(1, &Texture_ID); // Generate a texture
glBindTexture(GL_TEXTURE_2D, Texture_ID); // Bind that texture temporarily
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // (Actually, this one is the default)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Create the texture. We get the offsets from the image, then we use it with the image's
// pixel data to create it.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _width, _height, 0, GL_BGR, GL_UNSIGNED_BYTE, BMPPixelsBuffer);
// Unbind the texture
glBindTexture(GL_TEXTURE_2D, NULL);
// Delete the two buffers.
delete[] BMPHeaderBuffer;
delete[] BMPInfoBuffer;
delete[] BMPPixelsBuffer;
return true;
}