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

Author Topic: Error to load font  (Read 1882 times)

0 Members and 1 Guest are viewing this topic.

LonelyCoder

  • Newbie
  • *
  • Posts: 4
    • View Profile
Error to load font
« on: October 21, 2013, 10:38:40 am »
Hey, i got a problem to load a font in SFML.. The code is correct. The font is in a right place.. I don't understand what is the problem.. Can you help me?

That is my code:
#include "SFML/Graphics.hpp"
#include "SFML\Window.hpp"
#include "SFML\System.hpp"
#include <iostream>
using namespace std;

class FPS
{
       
public:
        int fps, counter;
        sf::Clock clock;
        FPS(int x = 0, int y = 0) {fps = x;counter = y;}

        void Update()
        { counter++; if(clock.getElapsedTime().asMilliseconds() >= 125)
        {fps = counter*8; counter = 0; clock.restart(); } }

};


int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
        FPS FPS(0,0);
       
        sf::Text text2;
        sf::Font font1;
       
        °°°°°°if(!font1.loadFromFile("arial.ttf"))
        {
                return 1;
        }
        text2.setFont(font1);
        text2.setString("Hello world");
        text2.setColor(sf::Color::White);
        text2.setPosition(0, 0);
        text2.setScale(2, 1);
       
        while (window.isOpen())
    {
               
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

                FPS.Update();
                std::cout << FPS.fps << std::endl;

                window.draw(text2);
                window.clear();
        window.display();
               
    }

    return 0;
}

That is my problem:


And that is my config and databases:




Regards. Lonely Coder
« Last Edit: October 21, 2013, 11:18:49 am by LonelyCoder »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Error to load font
« Reply #1 on: October 21, 2013, 10:45:25 am »
It's not in the right place.  You put it next to the code file, but source code doesn't run in place.  What runs is the executable file.  You need to put the font next to the executable.  If you don't know where that is, recompile it and pay attention to the output.

Also, IDEs can sometimes screw with the working directory for various reasons, so if that doesn't work be sure to try running the .exe directly (ie, double-clicking on it).

For the record, arial.ttf isn't a free font, so you'll want to use something else in your final product.  I know it doesn't matter now but the sooner you know the better.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Error to load font
« Reply #2 on: October 21, 2013, 10:46:07 am »
Check here: http://sfml-dev.org/tutorials/2.1/graphics-text.php

Under the section "Drawing text" there is a code example.

You are missing 1 very important line...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

LonelyCoder

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Error to load font
« Reply #3 on: October 21, 2013, 12:26:32 pm »
The problem keep.. I update the code, the problem it's on the line with ("°"), i'm also try to put the arial.ttf in paste debug and release, but don't work.. At last i didn't know that wasn't free. :S

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Error to load font
« Reply #4 on: October 21, 2013, 01:09:25 pm »
Make sure that you're not using release SFML libraries in debug mode.
Laurent Gomila - SFML developer

LonelyCoder

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Error to load font
« Reply #5 on: October 21, 2013, 03:24:23 pm »
Ty everyone, problem solved..
I had a mistake in my libraries, like Laurent said. Thanks one more time. :)