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

Author Topic: How to toggle fullscreen?  (Read 14551 times)

0 Members and 1 Guest are viewing this topic.

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
How to toggle fullscreen?
« 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?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to toggle fullscreen?
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
Re: How to toggle fullscreen?
« Reply #2 on: May 09, 2016, 01:03:27 am »
Yes, I forgot to include the crash info.

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

(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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: How to toggle fullscreen?
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
Re: How to toggle fullscreen?
« Reply #4 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.

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)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: How to toggle fullscreen?
« Reply #5 on: May 09, 2016, 01:26:54 am »
Your pointer is null (notice the 0x0000... as in you other thread).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
Re: How to toggle fullscreen?
« Reply #6 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.

TheGuerilla

  • Newbie
  • *
  • Posts: 27
  • Cynical Prick.exe
    • View Profile
    • Email
Re: How to toggle fullscreen?
« Reply #7 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 Github issue, which would lead me to believe that the issue is not limited to Linux.

Anyway, thanks for the help you guys!