SFML community forums

Help => Window => Topic started by: TheGuerilla on May 09, 2016, 12:41:37 am

Title: How to toggle fullscreen?
Post by: TheGuerilla on May 09, 2016, 12:41:37 am
So after reading up on fullscreen in SFML, I came up with this little function:
void SED::RenderHandle::SEF_SetFullscreen(bool fullscreen) {
        if (fullscreen)
                SEV_GameWindow->create(sf::VideoMode(SEV_WindowWidth, SEV_WindowHeight, 32), SEV_WindowTitle, sf::Style::Fullscreen);
        else
                SEV_GameWindow->create(sf::VideoMode(SEV_WindowWidth, SEV_WindowHeight, 32), SEV_WindowTitle);
}
Obviously it doesn't work, it just crashes the program and sets the monitor to 640 * 480 (the previous resolution), but my question is, what did I do wrong? When I read the documentation, it said that sf::Window::create can be used to recreate the window, not just initialize it. So I assumed recreating it with the fullscreen flag would work? I also tried it with using sf::VideoMode::getFullscreenModes()[0] instead of sf::VideoMode(SEV_WindowWidth, SEV_WindowHeight, 32) for fullscreen, and that seemed to keep the monitor size, but still crashed the program.

So I guess what I'm asking is how do you activate/toggle fullscreen?
Title: Re: How to toggle fullscreen?
Post by: Hapax on May 09, 2016, 12:51:40 am
You can change the "fullscreeniness" of a window by using create to re-create it with a fullscreen style, as you have done.

It is probable that the reason the fullscreen resorts to a default size is because the video mode that you are attempting to assigning is not a supported fullscreen mode. This is evident by getFullscreenModes stopping that occurring.

So, now you can re-create the window in fullscreen -
SEV_GameWindow->create(sf::VideoMode::getFullscreenModes()[0], SEV_WindowTitle, sf::Style::Fullscreen);
- the problem is the now occurring crash, about which you have not provided any details.
Title: Re: How to toggle fullscreen?
Post by: TheGuerilla on May 09, 2016, 01:03:27 am
Yes, I forgot to include the crash info.
(http://i.imgur.com/Mcy2qZT.png)
Sorry for the big image size, I had to capture the whole screen through ShareX because I couldn't get snipping tool to work there.

I also get this in the console window
(http://i.imgur.com/zjVAGfG.png)
(I was also unable to just straight copy the contents of the console for some reason...) I have no idea what either of those errors mean, so I'm quite clueless on this issue.
Title: Re: How to toggle fullscreen?
Post by: eXpl0it3r on May 09, 2016, 01:07:05 am
It crashes on your (I assume) screenshot function, where you call update(window, x, y) on a texture. What's your x and y value there? Sounds like you need to resize the texture as well in order to make a screenshot of larger window.
Title: Re: How to toggle fullscreen?
Post by: TheGuerilla on May 09, 2016, 01:22:21 am
Well, you're right, I wasn't resizing the texture, so I fixed that part by setting the window width/height variables after calling that function; then before the screen is rendered and shaders are applied, it runs this code to make sure that the texture is up to spec with the screen size
if (SEV_Screen.tex.getSize().x != SEV_WindowWidth || SEV_Screen.tex.getSize().y != SEV_WindowHeight) {
                SEV_Screen.tex.create(SEV_WindowWidth, SEV_WindowHeight);
                SEV_Screen.spr.setTexture(SEV_Screen.tex);
        }
A few more printf's revealed that SEV_WindowWidth/Height are the right size (1366 and 768 respectively), yet now I just get this error.
(http://i.imgur.com/lo52kiN.png)
That error occurs when
SEV_Screen.tex.update(*SEV_GameWindow);
is called; but I know that the texture is the right size. (I also tested the texture size)

(Btw thanks for the help thus far)
Title: AW: How to toggle fullscreen?
Post by: eXpl0it3r on May 09, 2016, 01:26:54 am
Your pointer is null (notice the 0x0000... as in you other thread).
Title: Re: How to toggle fullscreen?
Post by: TheGuerilla on May 09, 2016, 01:43:19 am
Sadly, its a valid pointer. I tested if it was either NULL or nullptr before calling that, and it is not a null pointer.
Title: Re: How to toggle fullscreen?
Post by: TheGuerilla on May 10, 2016, 05:36:20 am
(I'm assuming since this is a day later, this isn't a bump. Sorry if it is...)

Okay so I couldn't tell you what went wrong even if I wanted to, but what I did was after switching to fullscreen, I added a variable that waits a frame until re-adding the whole screen shader (the problem line), and that seemed to fix everything. I got the idea from this (https://github.com/SFML/SFML/issues/160) Github issue, which would lead me to believe that the issue is not limited to Linux.

Anyway, thanks for the help you guys!