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

Author Topic: Text is flickering  (Read 2022 times)

0 Members and 1 Guest are viewing this topic.

Miraz

  • Newbie
  • *
  • Posts: 8
    • View Profile
Text is flickering
« on: May 10, 2014, 09:58:50 am »
Hello !

Im drawing player position on top of screen and it's flickering, why ?

void RenderingThread(sf::RenderWindow* window)
{
    // Rendering loop
    cout << "Starting rendering loop"<< endl;
    while(window->isOpen())
    {
        // Clear window
        window->clear(sf::Color::White);

        // draw...
        window->draw(pSprite);
        window->draw(StaticText);

        // end current frame
        window->display();
    }
}

void InitSettings()
{
    if(font.loadFromFile("Prototype.ttf")){
     StaticText.setFont(font);
     StaticText.setCharacterSize(20);
     StaticText.setColor(sf::Color::Red);
     StaticText.setPosition(0,0);
     }

}

 

This line is inside my main loop
StaticText.setString("pPositionX: " + ToString(pPositionX) + " pPositionY: " + ToString(pPositionY) );

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email

Miraz

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Text is flickering
« Reply #2 on: May 10, 2014, 10:40:54 am »
Hi Jesper Juhl, it's still flickering ! i also limited my fps to 60.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Text is flickering
« Reply #3 on: May 10, 2014, 11:50:53 am »
Either use framerate limit or vertical sync. Never both at the same time - they interact badly (this is documented in the tutorials).

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Text is flickering
« Reply #4 on: May 10, 2014, 11:52:08 am »
I'm guessing you are using one thread for rendering and one thread for your "main" loop. And now both threads try to access the sf::Text instance at the same time = race condition = undefined behaviour = flickering.

If so, use a mutex to protect the variable or just don't use 2threads, because you won't gain any performance advantage out of it


AlexAUT

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Text is flickering
« Reply #5 on: May 10, 2014, 04:29:02 pm »
Multi-Threading will only be useful for larger projects to say the least so I wouldn't recommend using it either until you have to.  Could be the main cause of the issues you are having.  Now if you've completely split rendering and updating and have the two threads right you shouldn't be getting any flickering unless the update and rendering loops have too much time between them.
I have many ideas but need the help of others to find way to make use of them.

Miraz

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Text is flickering
« Reply #6 on: May 11, 2014, 04:34:13 pm »
Thank you for multiple responds, this forum is very helpfull when needed !

Indeed i use other thread to draw stuff on screen, i tought it is good to separate tasks on own threads. Im now clearing renderthread and implenting rendering in main loop. I also made decision to use VSYNC , not frame limiter.

I will update here if more problems occurs on text flickering!