#include "graphic_manager.hpp"
int main()
{
sf::RenderWindow app(sf::VideoMode(680, 680, 32), "Titan");
app.setFramerateLimit(60);
Graphic_Manager lolilol;
lolilol.loadTexture("mario.png");
sf::Sprite sprite(lolilol.getTexture(("mario.png")));
while (app.isOpen())
{
sf::Event event;
while(app.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
app.close();
break;
default:
break;
}
}
// Remplissage de l'écran (couleur noire par défaut)
app.clear();
app.draw(sprite);
// Affichage de la fenêtre à l'écran
app.display();
}
return EXIT_SUCCESS;
}
#include "graphic_manager.hpp"
Graphic_Manager::Graphic_Manager() : m_texture(), m_map(NULL)
{}
/*
-----------------------------------------------------------
Gestion des ressources
-----------------------------------------------------------
*/
bool Graphic_Manager::loadTexture(std::string chemin, bool oblige)
{
if(oblige == false)
{
std::map<std::string, sf::Texture>::iterator trouve = m_texture.find(chemin);
if(trouve == m_texture.end())
{
sf::Texture texture;
if(texture.loadFromFile(chemin))
{
m_texture[chemin] = texture;
std::cout << "ok";
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
else
{
sf::Texture texture;
if(texture.loadFromFile(chemin))
{
m_texture[chemin] = texture;
return true;
}
else
{
return false;
}
}
}
sf::Texture Graphic_Manager::getTexture(std::string chemin)
{
std::map<std::string, sf::Texture>::iterator trouve = m_texture.find(chemin);
if(trouve == m_texture.end())
{
std::cout << "pas ok";
return sf::Texture();
}
else
{
std::cout << "ok"
return m_texture[chemin];
}
}