SFML community forums

Help => Graphics => Topic started by: DEAGS on February 28, 2017, 08:39:40 am

Title: [Solved]Can't load font file while my CWD is right
Post by: DEAGS 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;
}

 

(http://p1.bqimg.com/4851/1db192484cc7f3ec.jpg)

(http://p1.bqimg.com/4851/d098560ac29829ce.jpg)

(http://p1.bqimg.com/4851/b0ca88cd1fa0bfea.jpg)

(http://p1.bqimg.com/4851/d71ae77fa82f55eb.jpg)
Title: Re: Can't load font file while my CWD is right
Post by: DEAGS 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?
Title: Re: Can't load font file while my CWD is right
Post by: Laurent 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.
Title: Re: [solved]Can't load font file while my CWD is right
Post by: DEAGS on February 28, 2017, 10:53:52 am
Didn't noticed that debug libs are suffixed with "-d", now it works well.