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

Author Topic: sf::RenderTexture and CPU 50%  (Read 1255 times)

0 Members and 1 Guest are viewing this topic.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
sf::RenderTexture and CPU 50%
« on: December 31, 2013, 02:43:49 am »
Hello
When you add in the draft RenderTexture, CPU immediately increased to 50%.

    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
    window.setVerticalSyncEnabled(true);

    sf::RenderTexture rendTexture;
    rendTexture.create(100, 100);

    while (window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::KeyPressed:

                    if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        window.close();
                break;

                default:
                break;
            }
        }

        rendTexture.clear();      
        rendTexture.display();  

        window.clear();
        window.display();
    }
 

Tell me, is this normal?

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: sf::RenderTexture and CPU 50%
« Reply #1 on: December 31, 2013, 03:04:58 am »
if it is
window.setVerticalSyncEnabled(true);
to replace it
window.setFramerateLimit(60);
then CPU usage falls

Tell me, what's wrong?

FRex

  • Hero Member
  • *****
  • Posts: 1846
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::RenderTexture and CPU 50%
« Reply #2 on: December 31, 2013, 04:03:24 am »
Vsync might not work in windowed mode, might be forcefully disabled by driver etc. while setFramerateLimit will surely limit the FPS to around 60 by sleeping. And without limiting framerate in one way or another your program runs as fast as it possibly can = 50% usage of CPU.

P.S. That event loop is slightly wrong usage of isKeyPressed.
Back to C++ gamedev with SFML in May 2023