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

Author Topic: Switch RenderWindow from Windowed<->Fullscreen (v1.6)  (Read 5659 times)

0 Members and 1 Guest are viewing this topic.

pkersey

  • Newbie
  • *
  • Posts: 6
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« on: November 30, 2011, 12:54:20 am »
Hello. I've been doing my first experiments with SFML 1.6 and came with this issue.
Would somebody please explain how do I switch from windowed mode to fullscreen, and then back to windowed mode? It's not working under Ubuntu 11.04, NVidia GTX 560.

Here's the code fragment.The mode switch was supposed to happen whenever the user pressed ALT+ENTER, and sometimes it works when going from windowed to fullscreen, but when trying to get back to windowed mode all I have is a black screen and I need to kill the process using the console to get my Desktop back.

EDIT: The problem doesn't happen under Win XP / Intel G33/G31 Express. The exact same code switches video modes perfectly as desired with those key presses.

Code: [Select]

            if (window.GetInput().IsKeyDown(sf::Key::LAlt) && window.GetInput().IsKeyDown(sf::Key::Return))
            {
                if (windowStyle == sf::Style::Fullscreen)
                {
                    windowStyle = sf::Style::Close;
                }
                else
                {
                    windowStyle = sf::Style::Fullscreen;
                }

                window.Create(sf::VideoMode(800, 600), "X", windowStyle);
            }


Thanks in advance!

sbroadfoot90

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« Reply #1 on: November 30, 2011, 11:47:25 am »
Not sure if this will fix what you described.

The way you are processing the input is by checking if the keys are currently pressed. If this code is being called every iteration of a loop (say 60 times a second), then the if statement will be entered say, 30 times if you hold the buttons down for half a second.

Instead what you should do is window.PollEvents(), and look for a KeyPressed event for sf::Key::Return, and && with window.GetInput().IsKeyDown(sf::Key::LAlt)

pkersey

  • Newbie
  • *
  • Posts: 6
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« Reply #2 on: November 30, 2011, 03:00:31 pm »
Thanks for your considerations, but sorry, I think your information is innacurate because, as I've reported previously, I've been using SFML 1.6. PollEvents() is SFML 2.0 only.

And I just found out the problem is Linux-only (see "EDIT:"), then it's presumably either a NVidia driver issue or a  platform-specific bug. The key combination switches video modes perfectly back and forth under Windows XP.

Thanks for your willing to help. If you have any other ideas, just let me know. Let's see what others have to say about this, too. Meanwhile I'll be researching the problem.

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« Reply #3 on: November 30, 2011, 03:38:46 pm »
Quote from: "pkersey"
Thanks for your considerations, but sorry, I think your information is innacurate because, as I've reported previously, I've been using SFML 1.6. PollEvents() is SFML 2.0 only.

sbroadfoot90's information is still valid. You don't seem to have read this tutorial on the tutorial section:
http://www.sfml-dev.org/tutorials/1.6/window-events.php
PollEvents is just the 2.0 version of GetEvent.

About your problem, I'm sorry, but I cannot help.

pkersey

  • Newbie
  • *
  • Posts: 6
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« Reply #4 on: November 30, 2011, 07:09:38 pm »
Let's make all things clear. First:

Quote from: "Tex Killer"
PollEvents is just the 2.0 version of GetEvent.


That was exactly what I wrote here, and you seem to have completely overlooked it:

Quote from: "pkersey"
PollEvents() is SFML 2.0 only.


Now this:

Quote from: "Tex Killer"

You don't seem to have read this tutorial on the tutorial section:
http://www.sfml-dev.org/tutorials/1.6/window-events.php


Sorry but you are wrong. I not only have read that as my code is following the instructions. I have read all the tutorials, the documentation, many forum posts and websites before started coding and also seeking any help, what I consider should be standard behaviour for everybody.

This topic has nothing to do with key events. Please let's keep in the subject.

Lastly:
Quote from: "Tex Killer"
About your problem, I'm sorry, but I cannot help.


Please don't get me wrong, but if you can't help others, don't just go posting anything that can't be of any use, moreover when you seem not to be reading the posts with due attention and don't care about the problem.

I'm not flaming you, again don't get it wrong, but your message was completely irrelevant. I'll be glad to be of any help to you in the future if the time comes. In fact I'm your colleague.

So people, back into the subject... any information?  Thanks.

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« Reply #5 on: November 30, 2011, 09:53:29 pm »
I've just commented that what sbroadfoot90 might help you, you would just had to use the right command to get the events. I said that it was SFML 2.0 only, and I said that there was another equivalent method for SFML 1.6, just that.
Sorry if I sounded offensive, that was not my intention.

pkersey

  • Newbie
  • *
  • Posts: 6
    • View Profile
Switch RenderWindow from Windowed<->Fullscreen (v1.6)
« Reply #6 on: November 30, 2011, 11:31:43 pm »
Quote from: "Tex Killer"
I've just commented that what sbroadfoot90 might help you, you would just had to use the right command to get the events.


No problem, pal. I didn't get it wrong. Let's just stick to the subject. You're always welcome, thanks.

pkersey

  • Newbie
  • *
  • Posts: 6
    • View Profile
NVidia driver is the probable culprit
« Reply #7 on: December 01, 2011, 12:05:49 am »
I tested the code in my friend's Linux box with a Radeon card and the problem doesn't happen. Currently researching ways on how to work around the issue. As this turns out not to be a SFML related problem, I'm considering this topic done at least for now.

Thanks everybody.