TankOs / SFGUI

Simple and Fast Graphical User Interface
zlib License
431 stars 62 forks source link

Font doesn't render properly #71

Closed Kostu96 closed 5 years ago

Kostu96 commented 5 years ago

I generate Visual Studio Solution to 0.4.0 from cmake, doesn't matter if I include default font or not. I build examples and they work just fine, bu when i link my project against built libs every font I tried is rendered like this 1 2

DrBarbare commented 5 years ago

Hi there,

Could you provide a bit more info to help narrow down the cause of your problem?

I don't think hardware info would be relevant, however, any compilation warning, OpenGL warnings or else would be welcome.

Kostu96 commented 5 years ago

Ok. SFML 2.5.1 binary release for Visual Studio 15 32 bit, static SFGUI 0.4.0, compiled with Visual Studio 15, in 32 bit as static lib. As for the font, I have used "lato" from google fonts, "arial" from my system, "linden_hill" shipped with sfgui, some random font from web, and of course sfgui default font. They work if I use them in example project, so I doubt it is the matter. Code is almost copy/paste from exemple so the same here. I currently test for my project configuration differences. The code:

include <SFML/GpuPreference.hpp>

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFGUI/SFGUI.hpp>
#include <SFGUI/Desktop.hpp>

class App {
public:
    App();
    void run();
private:
    void handleEvents();
    void update(const sf::Time & dt);
    void render();

    sf::RenderWindow m_renderWindow;
    sfg::SFGUI m_gui;
    sfg::Desktop m_guiDesktop;
};

App::App() : m_renderWindow(sf::VideoMode(1280, 720), "FPS: 0", sf::Style::Close) {
    m_renderWindow.setVerticalSyncEnabled(true);

    m_guiDesktop.SetProperties(
        "Window, Button {"
        "   FontName: assets/fonts/linden_hill.otf;"
        "   FontSize: 24;"
        "}"
    );

    auto guiWindow = sfg::Window::Create();
    guiWindow->SetTitle("This is the window title!");

    auto button = sfg::Button::Create("Hello");

    guiWindow->Add(button);
    m_guiDesktop.Add(guiWindow);
}

void App::run() {
    sf::Clock clock;
    while (m_renderWindow.isOpen()) {
        handleEvents();
        update(clock.restart());
        render();
    }
}

void App::handleEvents() {
    sf::Event e;
    while (m_renderWindow.pollEvent(e)) {
        m_guiDesktop.HandleEvent(e);

        switch (e.type)  {
        case sf::Event::Closed:
            m_renderWindow.close();
            break;
        }
    }
}

void App::update(const sf::Time & dt) {
    m_guiDesktop.Update(dt.asSeconds());

    // .. stuff updating fps counter ..
}

void App::render() {
    m_renderWindow.clear();
    m_gui.Display(m_renderWindow);
    m_renderWindow.display();
}

And these are errors I'm getting when I close sfml window. I do not get them when closing example. bez tytulu

EDIT: I run through project configuration of my project, example project and sfgui project, I checked every compiler and linker switch and problem still occures. I've created new project within cmake generated solution and problem occures also. I'm runnign out of ideas.

Kostu96 commented 5 years ago

I've found it. You have to resetGLStates for SFML window, otherwise this happens.

DrBarbare commented 5 years ago

Awesome! Glad you figured it out. I also noticed that the samples were chronically sending a lot of GL errors on closing BTW, in my project I solved that by making sure no draw calls were called after the window is closed. (In my case, that meant leaving the main loop after polling event, before updating or drawing.)