SFML community forums

Help => Window => Topic started by: JeZ-l-Lee on September 01, 2009, 04:14:07 pm

Title: Problem with centering SFML window on screen on Linux
Post by: JeZ-l-Lee on September 01, 2009, 04:14:07 pm
Hi,

How do I center an SFML created window on screen?
Looked in the documentation and searched the forum but cannot find it...

Thanks!
Title: Problem with centering SFML window on screen on Linux
Post by: Laurent on September 01, 2009, 04:19:36 pm
You can retrieve the total screen size with sf::VideoMode::GetDesktopMode(), then its just a matter of calculating the window position and applying it with window.SetPosition.
Title: Problem with centering SFML window on screen on Linux
Post by: JeZ-l-Lee on September 01, 2009, 04:42:13 pm
Thanks,
that works but on Linux for about 3 seconds
the entire screen flickers and CPU usage goes to 100%

For a 640x480 window, the source would be the following:
Code: [Select]
App.Create(sf::VideoMode(640, 480), "SFML/SDL-PerfecT+EnginE5.0GTSuperCharged");

App.SetPosition((sf::VideoMode::GetDesktopMode().Width/2)-320,
  (sf::VideoMode::GetDesktopMode().Height/2)-240);
Title: Problem with centering SFML window on screen on Linux
Post by: Nexus on September 02, 2009, 01:10:24 am
Quote from: "JeZ-l-Lee"
Thanks,
that works but on Linux for about 3 seconds
the entire screen flickers and CPU usage goes to 100%
Did you put the code inside a loop/was it executed multiple times?

Try a simple application where you just initialize a window, center it on the screen, call sf::Sleep() and wait some seconds (no loop or something at all)...
Title: Problem with centering SFML window on screen on Linux
Post by: JeZ-l-Lee on September 02, 2009, 02:22:12 am
Quote from: "Nexus"
Did you put the code inside a loop/was it executed multiple times?...
Hi,

I execute the centering only once, right after the screen setup.
Anyone else have any ideas?

PS - I'm on Linux Mint 7 Gloria with most current ATI proprietary display driver.
Title: Problem with centering SFML window on screen on Linux
Post by: Andershizzle on September 03, 2009, 07:27:53 am
Post your code?
Title: Problem with centering SFML window on screen on Linux
Post by: JeZ-l-Lee on September 03, 2009, 04:10:36 pm
Quote from: "Andershizzle"
Post your code?
Hi,

Here is the code:
Code: [Select]
App.Create(sf::VideoMode(640, 520), "The Final Option 100%[TM]");
App.SetPosition((sf::VideoMode::GetDesktopMode().Width/2)-320, (sf::VideoMode::GetDesktopMode().Height/2)-260);

My Operating System is Linux Mint 7 Gloria 32bit.
(running the most current ATI proprietary graphic driver)

Problem with above SFML window centering on screen
is that when it occurs at beginning, my entire screen flashes
and CPU usage goes to 100% for about 1-2 seconds.

I've ran this over 300 times in the past few days
and the SFML app has NEVER crashed.
(also the OS does not seem to be negatively affected by this either)

Any ideas?

PS - Same code and app runs fine on Windows XP / Vista...
Title: Problem with centering SFML window on screen on Linux
Post by: Andershizzle on September 03, 2009, 06:10:45 pm
What I meant is like, can you post the whole context of the code or most of it? I'll test this out on Windows and see what happens. But post up your whole code like... includes, int main, game loop etc.
Title: Problem with centering SFML window on screen on Linux
Post by: JeZ-l-Lee on September 03, 2009, 06:28:22 pm
Quote from: "Andershizzle"
What I meant is like, can you post the whole context of the code or most of it? I'll test this out on Windows and see what happens. But post up your whole code like... includes, int main, game loop etc.
Hi,

Um, I can not post to this forum the sources.
Its a multi file C++ Class based engine.

I've tested it on Windows XP/Vista (works 100%)

Thanks anyway...