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

Author Topic: [Solved]Can't load font file while my CWD is right  (Read 2462 times)

0 Members and 1 Guest are viewing this topic.

DEAGS

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
[Solved]Can't load font file while my CWD is right
« on: February 28, 2017, 08:39:40 am »
I've checked the working directory of my project(VS2015) and my font file is there, but the program still can't load it correctly. Informations in console are unreadable, maybe because of the encoding of my system. But, it seems their are some characters at the path string's head.

I'm sure that other parts of my code are correct, because when I commented font.loadFromFile() function call, the program works well.

here is the code:
#include <SFML/Graphics.hpp>
#include <imgui.h>
#include <imgui-SFML.h>
#include <SFML/System/Clock.hpp>


int main()
{
        sf::RenderWindow window(sf::VideoMode(1024, 768), "SFML works!", sf::Style::Default);
        window.setVerticalSyncEnabled(true);
        // &#32465;&#23450;ImGui
        ImGui::SFML::Init(window);

        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);

        // &#35835;&#21462;&#23383;&#20307;
        sf::Font font;
        font.loadFromFile("arial.ttf");


        sf::Clock deltaClock;
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        // ImGui&#22788;&#29702;&#20107;&#20214;
                        ImGui::SFML::ProcessEvent(event);
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                ImGui::SFML::Update(window, deltaClock.restart());
                //ImGui::ShowTestWindow();
                ImGui::Begin("test window 1");
                ImGui::Button("Look at this pretty button");
                ImGui::End();
                ImGui::Begin("test2");
                ImGui::Button("button");
                ImGui::End();

                window.clear(sf::Color(70, 120, 150));
                window.draw(shape);
                //window.draw(text);
                ImGui::Render();
                window.display();
        }
        ImGui::SFML::Shutdown();
        return 0;
}

 







« Last Edit: February 28, 2017, 10:56:25 am by DEAGS »

DEAGS

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Can't load font file while my CWD is right
« Reply #1 on: February 28, 2017, 10:13:46 am »
I found the answer at github, It seems I've mixed debug and release libs. But I don't know that at all. So where's the debug version libs? Do I need that?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Can't load font file while my CWD is right
« Reply #2 on: February 28, 2017, 10:33:45 am »
Everything is clearly explained in the "getting started" tutorial, read it carefully and things should work fine.
Laurent Gomila - SFML developer

DEAGS

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: [solved]Can't load font file while my CWD is right
« Reply #3 on: February 28, 2017, 10:53:52 am »
Didn't noticed that debug libs are suffixed with "-d", now it works well.
« Last Edit: February 28, 2017, 10:56:04 am by DEAGS »

 

anything