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

Author Topic: SFML 2.0, program window won't redraw unless it goes out of and back into focus  (Read 2303 times)

0 Members and 1 Guest are viewing this topic.

nestharus

  • Newbie
  • *
  • Posts: 2
    • View Profile
When I run the below program, it initially works perfectly. The program just writes whatever you are typing to the window. I wrote it for a tryout. When I hit CTRL+ALT+DELETE (doing a full screen****), the whole thing bugs. The program will only redraw the window whenever it goes out of and back into focus. It stays this way permanently (until I close it and start a new instance).

I'm not sure if I did something wrong here or if this is a problem with SFML.

Again, I run the program, I hit CTRL+ALT+DELETE, I hit cancel. I click on the window, I type text. The text does not appear. I click somewhere to bring the window out of focus. I click back on the window. The text is now up. I have to continue to do this to bring the text up.

When I run the program and don't hit CTRL+ALT+DELETE (bring about a full screen window thing on top of SFML's window), the program runs just fine. I type and the text appears.

Details of program: type letters like regular chat to make them appear. Backspace to delete. Enter to clear.

Attached to the post is the program in question (so that you don't have to setup a project or anything). It uses
    libsndfile-1.dll
    openal32.dll
    sfml-audio-2.dll
    sfml-graphics-2.dll
    sfml-network-2.dll
    sfml-system-2.dll
    sfml-window-2.dll

off topic
also, passing the string directly into setText makes the program crash.. I have to convert it to a c_str. Not sure if it's me again or if it's SFML being buggy =).
end off topic

Thank you for taking the time to read this post.

#include <SFML\Graphics.hpp>

#include <chrono>
#include <thread>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!", sf::Style::Close);
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    std::chrono::milliseconds interval(1000/32);

    window.setVerticalSyncEnabled(true);

    sf::Event event;
    sf::Text text("");
    text.setScale(.75, .75);
    text.setPosition(10, 80);
    text.setColor(sf::Color::White);

    std::string str = "";

    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
                        else if (event.type == sf::Event::TextEntered) {
                                if (static_cast<char>(event.text.unicode) == '\r') {
                                        str = "";
                                        text.setString("");
                                } //if
                                else if (static_cast<char>(event.text.unicode) == '\b') {
                                        str = str.substr(0, str.length() - 1);
                                        text.setString(str.c_str());
                                } //else if
                                else {
                                        str += static_cast<char>(event.text.unicode);
                                        text.setString(str.c_str());
                                } //else
                        } //else if
        }

        window.clear();
        window.draw(shape);
        window.draw(text);
        window.display();

        std::this_thread::sleep_for(interval);
    }
       
    return 0;
}
 

[attachment deleted by admin]

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
From the two header files you include I judge that you're using C++11 and thus probably using GCC 4.7. To use SFML 2 with GCC 4.7 you have to recompile SFML completly.

As for the code there's the function window.setFramerateLimit() so you don't have to do this on your own with std::this_thread::sleep_for(interval).
It's also not advised to use Vsync and a manual limiter. Use on or the other but not both!
When using std::string you should also include it's header.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nestharus

  • Newbie
  • *
  • Posts: 2
    • View Profile
hm.. I'm actually doing it in VS 2012.

including string stopped it from crashing when passing in a string. I just assumed that it included it within its own headers since the strings appeared to be working with the string header, but ok then ^)^.


I'd recompile it for VS 2012, but SFML 2 doesn't come with src atm : (.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
hm.. I'm actually doing it in VS 2012.
Then you will need to recompile or else you will continue to run into problems.
Quote
I'd recompile it for VS 2012, but SFML 2 doesn't come with src atm : (.
Download it from github. There is a full tutorial on how to do it on the site.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything