Hey folks!
It's just like the subject says; I've recently switched to 2.0 from 1.6 and I'm having an issue with loaded textures or images being the correct dimensions but a blank rectangle of white.
My code:
// TextureManager.h
#include "EngineComponents/TextureManager.h"
#include "DependantBase.h"
#include "MyException.h"
#include "StreamUtilities.h"
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Image.hpp>
std::ofstream TextureManager::log("logs/TextureManager.txt");
template<> TextureManager * TextureDependant::provider = NULL;
TextureManager::TextureManager(const std::string cfgPath) : textures(true)
{
log << "Texture/Image manager initializing, config path: " << cfgPath << std::endl;
std::ifstream file(cfgPath.c_str(), std::ios::binary);
if(!file)
{
log << "Error: could not load file: " << cfgPath << std::endl;
throw EngineException::fileNotFound;
}
std::string folderPath, extension;
StreamUtilities::Fetch<std::string>("folderPath", file, folderPath);
StreamUtilities::Fetch<std::string>("fileExtension", file, extension);
log << "Folder path: " << folderPath << "\nFile extension: " << extension << std::endl;
unsigned count = StreamUtilities::Count("image", file);
if(!count)
{
log << "Warning: No image tags found in file. Intended? (Probably not.)" << std::endl;
return;
}
std::string fileName;
for(unsigned i = 0; i < count; i++)
{
StreamUtilities::Fetch<std::string>("image", file, fileName);
StreamUtilities::Ignore("image", file);
sf::Texture * t = new sf::Texture;
if(!t->loadFromFile(folderPath + fileName + extension))
{
log << "Warning: unable to load file: " << folderPath << fileName << extension << std::endl;
delete t;
continue;
}
textures.Add(fileName, t);
}
log << "\nImage manager successfully initialized! Number of images loaded: " << textures.Size() << '\n' << std::endl;
}
TextureManager::~TextureManager()
{
log << "Image manager shutting down." << std::endl;
textures.Clean();
log << "Image manager freed memory; finished shutting down." << std::endl;
}
const sf::Texture * const TextureManager::Find(const std::string Name)
{
return static_cast<const sf::Texture*>(textures.Find(Name));
}
// Main.cpp
#include "Application.h"
#include "EngineComponents/TextureManager.h"
#include "DependantBase.h"
#include <fstream>
#include <SFML/Graphics.hpp>
int main()
{
Application app("config/Application.txt");
sf::Sprite s;
s.setTexture(*app.textures->Find(std::string("A")));
sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(s);
window.display();
}
return 0;
}
There are some parts there that don't make sense out of context; the Application class has a TextureManager* called textures. The TextureManager class has a PtrMap type I wrote that wraps the C++ list class; it's called textures and takes a bool on construction that determines whether the pointers should be deleted when the Manager goes out of scope.
I know that the textures' loadFromFile calls are returning true, so I don't know what's going on.