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

Author Topic: Problem with centering SFML window on screen on Linux  (Read 11415 times)

0 Members and 2 Guests are viewing this topic.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
Problem with centering SFML window on screen on Linux
« 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!
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with centering SFML window on screen on Linux
« Reply #1 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.
Laurent Gomila - SFML developer

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
Problem with centering SFML window on screen on Linux
« Reply #2 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);
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Problem with centering SFML window on screen on Linux
« Reply #3 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)...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
Problem with centering SFML window on screen on Linux
« Reply #4 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.
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Andershizzle

  • Newbie
  • *
  • Posts: 16
    • View Profile
Problem with centering SFML window on screen on Linux
« Reply #5 on: September 03, 2009, 07:27:53 am »
Post your code?

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
Problem with centering SFML window on screen on Linux
« Reply #6 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...
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Andershizzle

  • Newbie
  • *
  • Posts: 16
    • View Profile
Problem with centering SFML window on screen on Linux
« Reply #7 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.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
Problem with centering SFML window on screen on Linux
« Reply #8 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...
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com