SFML community forums

Help => Graphics => Topic started by: Mina66 on December 31, 2013, 02:43:49 am

Title: sf::RenderTexture and CPU 50%
Post by: Mina66 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?
Title: Re: sf::RenderTexture and CPU 50%
Post by: Mina66 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?
Title: Re: sf::RenderTexture and CPU 50%
Post by: FRex 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.