Hi,
I have modified the font from comic.ttf to arial.ttf in the following example code - please forgive...
When I try to use the following code from the example file graphics-fonts.cpp and I do not show the full directory path in if (!MyFont.LoadFromFile("arial.ttf", 50)) the system advises the following error "Failed to load font "arial.ttf" and exits the program.
If I place "C:/Windows/Fonts/arial.ttf", the program will execute correctly.
2 issues... Firstly, the program executes correctly as per above so I believe all libraries are linked correctly. Secondly, I have the arial.ttf font in the same directory with the executable so the program should be able to find "arial.ttf" without the full path.
I would like to not have the specify the full path for obvious reasons, but I can't figure out where I am going wrong.
My system is Windows 7 and using Netbeans 6.9...
Your help would be graciously received...
// Load a font from a file
sf::Font MyFont;
if (!MyFont.LoadFromFile("arial.ttf", 50))
return EXIT_FAILURE;
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create main window
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Fonts");
// Load a font from a file
sf::Font MyFont;
if (!MyFont.LoadFromFile("comic.ttf", 50))
return EXIT_FAILURE;
// Create a graphical string
sf::String Hello;
Hello.SetText("Hello !\nHow are you ?");
Hello.SetFont(MyFont);
Hello.SetColor(sf::Color(0, 128, 128));
Hello.SetPosition(100.f, 100.f);
Hello.SetRotation(15.f);
Hello.SetSize(50.f);
// You can also use the constructor
sf::String Bonjour("Salut !\nComment ça va ?", sf::Font::GetDefaultFont(), 30.f);
Bonjour.SetColor(sf::Color(200, 128, 0));
Bonjour.SetPosition(200.f, 300.f);
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Make the second string rotate
Bonjour.Rotate(App.GetFrameTime() * 100.f);
// Clear screen
App.Clear();
// Draw our strings
App.Draw(Hello);
App.Draw(Bonjour);
// Finally, display rendered frame on screen
App.Display();
}
return EXIT_SUCCESS;
}