GameKit  0.0.1a
C++ gamedev tools
TextureLoader.cpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: TextureLoader.cpp
5  *
6  * Description:
7  *
8  * Created: 16/03/2019 18:31:35
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #include "gk/core/XMLFile.hpp"
15 #include "gk/gl/Texture.hpp"
18 
19 namespace gk {
20 
21 void TextureLoader::load(const char *xmlFilename, ResourceHandler &handler) {
22  XMLFile doc(xmlFilename);
23 
24  tinyxml2::XMLElement *textureElement = doc.FirstChildElement("textures").FirstChildElement("texture").ToElement();
25  while (textureElement) {
26  std::string name = textureElement->Attribute("name");
27  std::string path = textureElement->Attribute("path");
28 
29  auto &texture = handler.add<gk::Texture>("texture-" + name);
30  texture.loadFromFile(path);
31 
32  textureElement = textureElement->NextSiblingElement("texture");
33  }
34 }
35 
36 }
37 
tinyxml2::XMLHandle FirstChildElement(const char *element)
Definition: XMLFile.hpp:30
T & add(const std::string &name, Args &&...args)
void loadFromFile(const std::string &filename)
Load the texture from a file on the disk.
Definition: Texture.cpp:54
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:30
void load(const char *xmlFilename, ResourceHandler &handler)