Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Font fails to load  (Read 3626 times)

0 Members and 1 Guest are viewing this topic.

vivid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Font fails to load
« on: May 05, 2014, 07:31:33 pm »
I'm using Visual Studio Express 2013 and I had to compile SFML 2.1 from the github repo.  Everything went fine, I was going through the tutorials and they all worked.  When I get to the one on fonts and text, trying to load the arial font fails everytime.  I've been using google and trying all suggestions.  I have the arial.ttf file where the .sln file is, where the .exe is, and where the .vcxproj, and none of them work.  I also tried using an absolute filename to the arial.ttf in the Windows\Fonts folder, and nothing.

When I try to run the program from explorer or the command prompt it crashes and I can't see what messages are displayed other than a bunch of hyroglyph looking characters.  But when I run it in the IDE, it still does the same thing, but I can scroll up and see the error message that is printed:
Quote
Failed to load font X8 arial.ttf
And followed by a bunch of strange looking characters.  Any ideas?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Font fails to load
« Reply #1 on: May 05, 2014, 07:33:40 pm »
Show us some complete and minimal code that reproduces the issue.

vivid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Font fails to load
« Reply #2 on: May 05, 2014, 07:35:23 pm »
Sorry I forgot to post it before... :-[
// Text.cpp
// An example of drawing text/using fonts with SFML.
#include <SFML\Graphics.hpp>
#include <iostream>

int main()
{
        // Create a font object and load the arial font into it.
        sf::Font font;
       
        if(!font.loadFromFile("arial.ttf"))
        {
                std::cerr << "Error: \"could not load font 'arial.ttf'\"!\n";
                return -1;
        }
       
        // Create the render window to draw in.
        sf::RenderWindow app(sf::VideoMode(800, 600), "SFML Text");

        // An event object for handling window events.
        sf::Event event;

        // Run the program as long as the window is open.
        while(app.isOpen())
        {
                // Check all events since the last loop iteration.
                while(app.pollEvent(event))
                {
                        // Check if the close event was triggered.
                        if(event.type == sf::Event::Closed)
                        {
                                app.close();
                        }
                }

                // Clear the window with a black color.
                app.clear(sf::Color::Black);

                // All drawing code goes here...
                //app.draw();

                // End the current frame and swap the video buffers.
                app.display();
        }
}
 

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Font fails to load
« Reply #3 on: May 05, 2014, 08:19:30 pm »
Sounds like you mixed debug/release libs. Take another look at the tutorial and pay close attention to the part about mixing debug/release libs.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

vivid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Font fails to load
« Reply #4 on: May 05, 2014, 10:03:09 pm »
Thank you my friend, you were indeed correct.

 

anything