-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver_LoadTextures.hpp
More file actions
140 lines (106 loc) · 3.67 KB
/
Driver_LoadTextures.hpp
File metadata and controls
140 lines (106 loc) · 3.67 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
#pragma once
#ifndef TERMINAL_LOAD_TEXTURES_HPP
#define TERMINAL_LOAD_TEXTURES_HPP
#include <string>
#define THREADED_TEXTURE_LOADING
#if defined THREAD_ALL || defined THREADED_TEXTURE_LOADING
#include <thread>
#endif
#include <Graphics/Texture/TextureLoader.hpp>
#include <Graphics/Texture/Texture.hpp>
/* WorldSim: Driver_LoadTextures.hpp
#include "Driver_LoadTextures.hpp"
Called from Driver::init().
These vars are global.
All texture refs start with TEX_, and then use the path and filename from the textures folder.
Requires OpenGL headers.
*/
void SetColor(int value){
#ifdef WILDCAT_WINDOWS
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), value);
#endif
}
static Texture TEX_TERMINAL;
static Texture TEX_TERMINAL_GRID;
static Texture TEX_TERMINAL_BKG;
static Texture TEX_MCOM_CITY;
static Texture TEX_MCOM_CITY_RIP;
static Texture TEX_MCOM_MISSILE;
static Texture TEX_MCOM_MISSILE_RIGHT;
static Texture TEX_MCOM_MISSILE_RIP;
Texture texRuntime; /* Test of runtime graphics creation. */
void loadTextureVerbose(const std::string _path, Texture* _texture)
{
std::cout<<"Loading: "<<_path<<".\n";
if(loadTextureNearestNeighbour(_path,_texture)==false)
{ std::cout<<"Error loading "<<_path<<".\n"; }
}
void preloadTextureVerbose(const std::string _path, Texture* _texture)
{
if(loadTextureNearestNeighbour(_path,_texture)==false)
{
SetColor(4);
std::cout<<"Loading: "<<_path<<": FAIL.\n";
SetColor(7);
}
else
{
std::cout<<"Loading: "<<_path<<": SUCCESS.\n";
}
}
void loadTextures() // Testing some multithreading here. Probably shouldn't because a texture atlas would be better
{
if(const char* env_p = std::getenv("WILDCAT_TEXTURES"))
std::cout << "Your PATH is: " << env_p << '\n';
static std::string texPath = std::getenv("WILDCAT_TEXTURES");
texPath+="\\Terminal\\";
std::cout<<"texpath: "<<texPath<<"\n";
//#undef THREADED_TEXTURE_LOADING
#if defined THREAD_ALL || defined THREADED_TEXTURE_LOADING
std::thread t1( []
{
#endif
// LOAD MENU TEXTURES
preloadTextureVerbose(texPath+"HaruhiTerminal2.png",&TEX_TERMINAL);
preloadTextureVerbose(texPath+"43Grid.png",&TEX_TERMINAL_GRID);
preloadTextureVerbose(texPath+"Background5.png",&TEX_TERMINAL_BKG);
// preloadTextureVerbose("Textures/Game/cityt2.png",&TEX_MCOM_CITY);
// preloadTextureVerbose("Textures/Game/cityrip.png",&TEX_MCOM_CITY_RIP);
// preloadTextureVerbose("Textures/Game/missilet2.png",&TEX_MCOM_MISSILE);
// preloadTextureVerbose("Textures/Game/missilert.png",&TEX_MCOM_MISSILE_RIGHT);
// preloadTextureVerbose("Textures/Game/missileript.png",&TEX_MCOM_MISSILE_RIP);
#if defined THREAD_ALL || defined THREADED_TEXTURE_LOADING
});
std::thread t2( []
{
#endif
#if defined THREAD_ALL || defined THREADED_TEXTURE_LOADING
});
#endif
#if defined THREAD_ALL || defined THREADED_TEXTURE_LOADING
t1.join();
t2.join();
#endif
bindNearestNeighbour(&TEX_TERMINAL,COMPRESS_TEXTURES);
bindNearestNeighbour(&TEX_TERMINAL_GRID,COMPRESS_TEXTURES);
bindNearestNeighbour(&TEX_TERMINAL_BKG,COMPRESS_TEXTURES);
texRuntime.create(320,200,0,true);
// load font
/* Load font */
Png fontPng;
int fileSize;
//unsigned char* fileData = FileManager::getFile(texPath+"Font/8x8/8x8 Transparent v4 plus junk white.png",&fileSize);
unsigned char* fileData = FileManager::getFile(texPath+"Font/8x8/C64-6.png",&fileSize);
if ( fileData == 0 )
{
std::cout<<"ERROR: Font PNG did not load.\n";
}
else
{
fontPng.load(fileData,fileSize);
if(font8x8.loadData(&fontPng,8,8)==false)
{ std::cout<<"ERROR: Font did not load.\n"; }
delete [] fileData;
}
}
#endif