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

Author Topic: RenderWindow::Display is absurdly slow when drawing nothing  (Read 3008 times)

0 Members and 1 Guest are viewing this topic.

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
RenderWindow::Display is absurdly slow when drawing nothing
« on: September 16, 2011, 02:08:46 am »
Essentially, if I create a RenderWindow and call its Display() function, it will cause the game to hang for 15 or 10 seconds for two out of every three calls.  Here is the stripped-down code:

Code: [Select]
sf::RenderWindow App;
int main()
{
App.Create(sf::VideoMode(800, 600), "");
    while (App.IsOpened())
    {
double i = clock();
App.Display();
printf("%f\n",(clock()-i)/CLOCKS_PER_SEC);
    }
   
}


and here is what it prints:

Code: [Select]
00.099000
00.002000
15.164000
10.096000
00.003000
15.142000
10.091000
00.002000
15.155000
10.098000
00.005000
15.148000
10.088000
00.003000
15.149000
10.089000
00.003000
15.173000
10.095000
00.004000
15.157000
10.092000
00.004000 (etc.)


I'm stumped here, and even stranger is that this issue just popped up recently, and I have no clue what caused it.  I feel I should also mention that I don't have any issues with the pre-compiled examples, so it's not just an issue my computer has with RenderWindow.  I'm still using SFML 1.6, not 2.0, if it helps, and I'm compiling using Visual Studio 2008.  Any help would be greatly appreciated.  (I assume this question goes here, right...?)

Richy19

  • Full Member
  • ***
  • Posts: 190
    • View Profile
RenderWindow::Display is absurdly slow when drawing nothing
« Reply #1 on: September 16, 2011, 02:14:47 am »
Try the same test but drawing the text to screen, writing to the console takes alot of time (computer wise). also use std::cout not printf, printf is for C not c++

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
RenderWindow::Display is absurdly slow when drawing nothing
« Reply #2 on: September 16, 2011, 02:18:30 am »
Quote from: "Richy19"
Try the same test but drawing the text to screen, writing to the console takes alot of time (computer wise).


It does this regardless of whether or not I'm writing to the console.  Either way I doubt doing so would take 15 seconds.

Quote from: "Richy19"
also use std::cout not printf, printf is for C not c++


Eh, it's just a bad habit, I guess.  It doesn't really affect anything here, though.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
RenderWindow::Display is absurdly slow when drawing nothing
« Reply #3 on: September 16, 2011, 07:47:46 am »
You should try to add an event loop. The window behaves strangely when you don't give it a chance to process its events.
Laurent Gomila - SFML developer

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
RenderWindow::Display is absurdly slow when drawing nothing
« Reply #4 on: September 16, 2011, 05:20:37 pm »
The event loop doesn't make a difference either; it was actually one of the things that I removed when I posted the stripped-down code.

Robert42

  • Newbie
  • *
  • Posts: 31
    • View Profile
RenderWindow::Display is absurdly slow when drawing nothing
« Reply #5 on: September 16, 2011, 10:03:15 pm »
try to set a framerate limit sf::Window::SetFramerateLimit before entering the main loop with a limit < 1000 (for example 120).   and don't forget handle events.

That was the solution for me

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
RenderWindow::Display is absurdly slow when drawing nothing
« Reply #6 on: September 16, 2011, 10:58:26 pm »
That doesn't seem to be working either, unfortunately, but thank you.