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

Author Topic: Stuttering / slowdown in windowed mode  (Read 2573 times)

0 Members and 1 Guest are viewing this topic.

SriK

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Stuttering / slowdown in windowed mode
« on: May 24, 2012, 06:53:40 am »
Hi,

I've been having a problem with erratic framerate and stutter/slowdown in SFML. This problem has happened both in previous versions of SFML as well as the current release candidate of SFML-2, which I just switched to after hearing some timing issues were fixed. Weirdly enough, this only seems to happen in windowed mode -- everything works fine in fullscreen (no stutter at all.) Enabling VSync, frame limiting to 60fps, or both doesn't help the stuttering, and even without any limiting at all the program still slows down (e.g. it'll be running at 500fps for a small bit then slow down to 100 or lower, then speed up again, etc.)

Here's a small test case (I first encountered this problem when working on a relatively large-scale game project:)

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

int SCR_WIDTH = 640;
int SCR_HEIGHT = 480;
bool FULLSCREEN = false;
bool VSYNC = true;
bool LIMIT_FRAMERATE = false;
int FRAMERATE = 60;

int main()      {
        unsigned long style = ((FULLSCREEN == true) ? sf::Style::Fullscreen : sf::Style::Close);
        sf::RenderWindow game(sf::VideoMode(SCR_WIDTH,SCR_HEIGHT,32), "Test", style);

        game.setVerticalSyncEnabled(VSYNC);
        if (LIMIT_FRAMERATE) game.setFramerateLimit(FRAMERATE);

        sf::Clock frameClock;

        sf::Image redSquareImg;
        redSquareImg.create(128, 128, sf::Color(sf::Color::Red));
        sf::Texture redSquareTex;
        redSquareTex.loadFromImage(redSquareImg);
        sf::Sprite redSquare;
        redSquare.setTexture(redSquareTex);
        int squareX = 20, squareY = 20;

        while (game.isOpen())   {
                frameClock.restart();

                game.clear();

                redSquare.setPosition(squareX, squareY);
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) squareX -= 2;
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) squareX += 2;
                game.draw(redSquare);

                game.display();
                int ft =  1000 / frameClock.getElapsedTime().asMilliseconds();

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) game.close();
                std::cout << ft << std::endl;
        }
}

Running Windows 7, graphics card is NVIDIA GeForce GTX 260. Any help would be greatly appreciated.

Thanks,
Sri
« Last Edit: May 24, 2012, 07:57:22 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Stuttering / slowdown in windowed mode
« Reply #1 on: May 24, 2012, 07:58:31 am »
Does it help if you add an event loop?
Laurent Gomila - SFML developer

SriK

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Stuttering / slowdown in windowed mode
« Reply #2 on: May 24, 2012, 05:07:41 pm »
If you mean just polling for events in a loop like so:

        sf::Event ev;
        while (game.pollEvent(ev))      {
            if (ev.type == sf::Event::Closed) game.close();
        }

...then no, it doesn't I'm afraid.
« Last Edit: May 24, 2012, 05:09:05 pm by Laurent »

SriK

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Stuttering / slowdown in windowed mode
« Reply #3 on: May 25, 2012, 12:06:56 am »
I just tried the test code on a computer running Ubuntu Linux 11.04, graphics card GeForce 9400 -- no stuttering or slowdown with any configuration setting (vsync, frame limiting, neither, or both.) Actually, here's a straight up dump of the specs, since I can do that easily on here. I'll post something similar for the PC I made the original post on when I get back home in a bit. I'd really like to solve this issue if possible, I don't want to have to force fullscreen on players (and testing my game in windowed mode is also more convenient for me anyway.)

EDIT: I should probably also mention that, on the Windows PC at least, this is something that seems to happen with every SFML program I open (including e.g. the demos) not just the ones I write. Also, the stutter occurs at a rate of approximately once per second, if that helps.
« Last Edit: May 25, 2012, 05:37:54 am by SriK »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Stuttering / slowdown in windowed mode
« Reply #4 on: May 25, 2012, 10:31:59 am »
Does your PC run with the latest graphic card driver?
Also try to run some other (native) OpenGL applications and see if they got the stuttering too.

In the end it's not something caused by SFML because the demos work all on most PCs. ;)
Is there an application on your PC that uses a big percentage of your CPU from time to time?
And what antivirus software have you running? Maybe deactivate it once and try again.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/