OK update. I re did the class for the most part so it works a bit different.
I have no compile errors, no debug errors, but also no text displays. ... Not sure why. It seems almost like the font is blank, but I receive no errors when loading the font. I get no errors at all really. But as I said, No text is printed to the screen. I'll post the updated code.
.cpp
#include "stdafx.h"
#include "DevHudDisplay.h"
DevHud::DevHud()
{
Enabled = false;
//Setting up defaults for font/text elements.
fontUtils.SetupText(fontUtils.DevHud,DevHudFont,CurserPosText);
CurserPosText.setFont(DevHudFont);
CurserPosText.setPosition(0,0);
}
void DevHud::gatherData(EngineWindow& glWindow,sf::Event& e)
{
consoleLog.info("running_DH");
if(e.type == sf::Event::EventType::KeyPressed)//If we detect a tilde toggle the enable variable.
{
if(e.key.code == sf::Keyboard::Tilde)
{
ToggleDevHud();
}
}
if(Enabled)//Only set the vars if its enabled.
{
consoleLog.info("Enabled");
setVars(glWindow);
}
}
void DevHud::setVars(EngineWindow& glWindow)
{
//Mouse Position Vars
mouse_pos = sf::Mouse::getPosition(glWindow);
std::stringstream PositionLine;
PositionLine << "Mouse Pos: " << "X: " << mouse_pos.x << " Y: " << mouse_pos.y;
MousePos = PositionLine.str();
CurserPosText.setString(MousePos);
}
void DevHud::ToggleDevHud()
{
if(Enabled)
{
Enabled = false;
}else if(!Enabled){
Enabled = true;
}
}
void DevHud::Draw(EngineWindow& glWindow)
{
if(Enabled)//Only draw to the render window if enabled.
{
glWindow.draw(CurserPosText);
}
}
.h
#ifndef DEVHUDDISPLAY_H
#define DEVHUDDISPLAY_H
#include "stdafx.h"
#include "WindowManagment.h"
#include "Genesis.h"
#include "ConsoleUtils.h"
class DevHud{
Log consoleLog;
Validate validate;
FontUtils fontUtils;
public:
DevHud();
void gatherData(EngineWindow&,sf::Event&);
void ToggleDevHud();
void Draw(EngineWindow&);
private:
bool Enabled;
sf::Text CurserPosText;
sf::Font DevHudFont;
sf::String MousePos;
sf::Vector2i mouse_pos;
void setVars(EngineWindow&);
};
#endif
The function that sets up the font:
void FontUtils::SetupText(TextStyle s,sf::Font& f,sf::Text& t)
{
Log consoleLog;
if(s == FontUtils::DevHud)
{
consoleLog.info("Loading the Font");
if(!f.loadFromFile("Resource/Font/visitor2.ttf"))
{
consoleLog.critical("Unable to load font file!");
}
t.setColor(sf::Color::Green);
t.setCharacterSize(40);
}
}
Calling Point
DevHud devHud;
while(true)
{
sf::Event e;
while(glWindow.pollEvent(e))
{
ConsoleLog.info("EVENT CALLED");
devHud.gatherData(glWindow,e);
if((e.type == sf::Event::EventType::KeyPressed)&&(e.key.code == sf::Keyboard::Escape))
{
return;
}
}
glWindow.clear();
devHud.Draw(glWindow);
glWindow.display();
}
I moved around some console logs and checked. Every part of the code is running. Its just not displaying anything. o.O
I'll keep tinkering but if you see something wrong, do tell me!