GameKit
0.0.1a
C++ gamedev tools
source
resource
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
"
16
#include "
gk/resource/ResourceHandler.hpp
"
17
#include "
gk/resource/TextureLoader.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
gk::ResourceHandler
Definition:
ResourceHandler.hpp:26
Texture.hpp
gk::XMLFile::FirstChildElement
tinyxml2::XMLHandle FirstChildElement(const char *element)
Definition:
XMLFile.hpp:30
gk::ResourceHandler::add
T & add(const std::string &name, Args &&...args)
Definition:
ResourceHandler.hpp:29
gk
Definition:
AudioPlayer.hpp:21
TextureLoader.hpp
gk::Texture::loadFromFile
void loadFromFile(const std::string &filename)
Load the texture from a file on the disk.
Definition:
Texture.cpp:54
ResourceHandler.hpp
gk::Texture
Image living on the graphics card that can be used for drawing.
Definition:
Texture.hpp:30
XMLFile.hpp
gk::XMLFile
Definition:
XMLFile.hpp:23
gk::TextureLoader::load
void load(const char *xmlFilename, ResourceHandler &handler)
Definition:
TextureLoader.cpp:21
Generated by
1.8.12