I'm relatively new to SFML and I've been going through the 2.0 documentation for the past couple of days. That being said, I've been trying to unsuccessfully render text to my renderWindow, which I create as follows:
window.create(sf::VideoMode(width, height, 32), title, sf::Style::Close);
window.setFramerateLimit(60);
This works fine as a window is rendered.
Then, for debug purposes I attempt to draw text while the window is open with:
window.clear(sf::Color::White);
sf::Text text;
text.setString("TTT");
text.setCharacterSize(12);
text.setColor(sf::Color::Black);
text.setPosition(10, 10);
window.draw(text);
window.display();
The code compiles fine, however I just get a white window with no text. I have successfully linked to the graphics and window package for SFML 2.0.
Thanks in advance.
Thanks for that.
However, I now use the following code, yet it still only displays a white screen:
window.clear(sf::Color::White);
sf::Text text;
text.setString("Hello");
text.setFont(font);
text.setCharacterSize(50.f);
window.draw(text);
window.display();
(I have also tried setting the position of the font to see if that was it; alas it wasn't)
After loading the font in the game's beginning:
font.loadFromFile("resources/arial.ttf");
The font face loads fine as no warnings are displayed in the game's console.
void Render::createWindow(unsigned int w, unsigned int h, string title) {
//Create new rendering window
width = w;
height = h;
window.create(sf::VideoMode(width, height, 32), title, sf::Style::Close);
window.setFramerateLimit(60);
font.loadFromFile("resources/arial.ttf");
}
void Render::render() {
//Render
window.clear(sf::Color::White);
sf::Text text;
text.setString("Hello");
text.setFont(font);
text.setCharacterSize(50.f);
text.setPosition(10.f, 10.f);
window.draw(text);
window.display();
}
And my main game loop:
Render::createWindow(800, 600, "Caption");
while(Render::window.isOpen()) {
currentTime = clock->restart().asSeconds();
fps = 1.f / currentTime;
//Event polling
sf::Event event;
while (Render::window.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
Render::window.close();
}
}
lastTime = currentTime;
Render::render();
}
Thanks again.