Implemented void load_interface_textures
This commit is contained in:
@@ -142,4 +142,79 @@ struct complete_texture
|
||||
|
||||
unsigned char* pixels;
|
||||
};
|
||||
|
||||
// Load the interface textures into a std::map mapping the interface texture's
|
||||
// name to it's complete_texture*.
|
||||
|
||||
std::map<std::string, complete_texture*> interface_textures;
|
||||
|
||||
void load_interface_textures()
|
||||
{
|
||||
for (int i = 0; i < all_gui.size(); i++)
|
||||
{
|
||||
// Load the texture.
|
||||
|
||||
std::string path = "../gui/" + all_gui[i] + ".png";
|
||||
|
||||
GLuint gui_texture;
|
||||
|
||||
glGenTextures(1, &gui_texture);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, gui_texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
int gui_x_res;
|
||||
int gui_y_res;
|
||||
|
||||
int gui_channels;
|
||||
|
||||
unsigned char* gui_data = stbi_load(path.c_str(), &gui_x_res, &gui_y_res, &gui_channels, 0);
|
||||
|
||||
if (!gui_data)
|
||||
{
|
||||
std::cout << "Could not load \"" << path << "\" using stbi_load." << std::endl;
|
||||
|
||||
exit(18);
|
||||
}
|
||||
|
||||
if (gui_channels != 4 && gui_channels != 3)
|
||||
{
|
||||
std::cout << "Channel count of \"" << path << "\" (" << gui_channels << ") does not match any of the expected channel counts (3 or 4)." << std::endl;
|
||||
|
||||
exit(19);
|
||||
}
|
||||
|
||||
if (gui_channels == 4)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, gui_x_res, gui_y_res, 0, GL_RGBA, GL_UNSIGNED_BYTE, gui_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, gui_x_res, gui_y_res, 0, GL_RGB, GL_UNSIGNED_BYTE, gui_data);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
// Generate a complete_texture* to store in interface_textures.
|
||||
|
||||
complete_texture* gui_complete = new complete_texture();
|
||||
|
||||
gui_complete->storage = gui_texture;
|
||||
|
||||
gui_complete->x_res = gui_x_res;
|
||||
gui_complete->y_res = gui_y_res;
|
||||
|
||||
gui_complete->channels = gui_channels;
|
||||
|
||||
gui_complete->pixels = gui_data;
|
||||
|
||||
// Add the complete_texture entry to interface_textures.
|
||||
|
||||
interface_textures.emplace(all_gui[i], gui_complete);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user