Hi, I've problem with the use of pointers of Font and Text classes.
[SOLVED] *click*I searched forum and found this similar
topic, but I'm not sure what I'm doing wrong in my code.
#include <iostream>
#include <cstdlib>
#include "SFML/Graphics.hpp"
#include "SFML/Audio.hpp"
#include "SFML/Network.hpp"
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "Hello world");
cout << "Window has been created" << endl;
sf::Font* font;
if (!font->loadFromFile("/home/jaffa/workspace/hello-world/fonts/ubuntu-font-family/Ubuntu-R.ttf")) {
cout << "Couldn't load font!" << endl;
} else {
cout << "Font has been loaded!" << endl;
}
sf::Text* text;
text->setFont(*font);
cout << "Text font has been set" << endl;
text->setString("Hello world");
cout << "Text string has been set" << endl;
text->setColor(sf::Color::Blue);
cout << "Text color has been set" << endl;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
cout << "pollEvent" << endl;
if (event.type == sf::Event::Closed) {
window.close();
}
}
cout << "Trying to clear window" << endl;
window.clear(sf::Color::Black);
cout << "Trying to draw text" << endl;
window.draw(*text);
cout << "Trying to display" << endl;
window.display();
cout << "End of the current frame" << endl;
}
return EXIT_SUCCESS;
}
When I run this code app's, window appeared and immediately closed. In my console I saw:
Window has been created
The program has unexpectedly finished.
Can someone show me how I should use these classes with pointers?