| Summary: | Difficult to set desired window size after leaving full screen | ||
|---|---|---|---|
| Product: | SDL | Reporter: | buckyballreaction |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | amaranth72, david, icculus, norfanin, ny00 |
| Version: | 2.0.0 | Keywords: | target-2.0.0 |
| Hardware: | All | ||
| OS: | All | ||
|
Description
buckyballreaction
2013-07-12 22:56:49 UTC
Tagging this bug with target-2.0.0, Priority 2. --ryan. I'm not sure about this, but may it be related to the following bug report by chance? (Sample code is currently attached there.) https://bugzilla.libsdl.org/show_bug.cgi?id=1868 It's a bit late at night here, so I might be missing something, but why are you calling SDL_SetWindowSize in response to SDL_WINDOWEVENT_RESIZED events? By the time you've got the message, the window should be set up with the correct size. If you need to update state based on the window's size changing, you can always listen for both SDL_WINDOWEVENT_RESIZED and SDL_WINDOWEVENT_SIZE_CHANGED to get the new size. You'll get a SIZE_CHANGED event even when you call SDL_SetWindowSize. -- David I admit I may be doing something wrong, but I thought SDL_WINDOWEVENT_RESIZED was triggered like the old SDL 1.2 SDL_VIDEORESIZE event: when a window manager was resized the event was sent and you were supposed to use SDL_SetVideoMode() on the new size given in the event. Similarly I've been using the SDL2 event and call SDL_SetWindowSize() on the new size. Are you saying that this is not the case anymore? I'm far from an expert on the SDL2 render API, but you certainly don't need to do anything other than change your viewport when using OpenGL. I suspect the Render API will handle everything for you (if not, it has a SDL_RenderSetViewport function, which is probably the right thing to call), though if you're using SDL_GetWindowSurface, I think you'll need to call that every time the window is resized as you might get a new surface. Try it and see! -- David Indeed, SDL_WINDOWEVENT_RESIZED is (in theory) only triggered when the window *actually* resizes. Calling SDL_SetWindowSize in response to that event is (in theory) redundant. There's a bug exclusive to Windows when exiting fullscreen where the window won't resize back to its original size properly, even though it still sends an SDL_WINDOWEVENT_RESIZED event: https://bugzilla.libsdl.org/show_bug.cgi?id=2067 But that's just a bug, and it doesn't happen on other platforms. The problem is that I have an OpenGL game and if the window manager resizes the window (and thus triggers that event), I need to scale everything inside in response (because the resize was *not* triggered by the game, rather the WM). Are you saying I'm not supposed to use SDL_WINDOWEVENT_RESIZED? I need to get the dimensions of the newly resized window somehow (which end up being wrong on Windows/OSX). I understand that this would be unnecessary if the game video mode was only changeable within the game (completely controlled from the game), but our game is scalable and users use the window manager outline to set the size - which is a nice feature for a pure-OpenGL game. You should definitely use SDL_WINDOWEVENT_RESIZED to change your game's behaviour to match the new window size, e.g. call glViewport again and re-create resources (textures used as render targets and such) at the appropriate size. You shouldn't call SDL_SetWindowSize in response to SDL_WINDOWEVENT_RESIZED, because a window size change is what triggers the event in the first place. SDL is telling you "the window has been resized", not "the window should be resized". I guess the assumption is that you don't need an event if you're the one calling SDL_SetWindowSize. You already know what the window size is going to be. The outdated resized event is a bit irritating, I guess. Like mentioned above, if you always want an event, use SDL_WINDOWEVENT_SIZE_CHANGED. This got a lot more complicated with the window limits that got added sometime before the 2.0.0 release and I think the logic in SDL_SetWindowSize has to be looked at again. It would also be helpful if there's some guideline if this function always overrides the window limits (user-set and/or system defaults) or if it has to respect them. Just to recap, you should listen to SDL_WINDOWEVENT_SIZE_CHANGED if you just want to update your OpenGL state whenever the window size changes for any reason. I just added code to respect the window min/max size in the SDL_SetWindowSize() call, and you can call it to change the windowed size anytime. Yes. OK. I finally figured out the discrepancy- We support both SDL 1.2 and 2.0 (because of trying to be compatible with most Linux distros). Because of this, we handle the special case of resizing a window in window mode via SDL_VIDEORESIZE (in 1.2); however, I had thought that I could do the same with SDL_WINDOWEVENT_RESIZED (in 2.0), but it turns out that this new event is triggered much more frequently, not just in the case of resizing a windowed window. To make it more like the 1.2 behavior, we now call SDL_FlushEvent(SDL_WINDOWEVENT) whenever we call SDL_SetWindowSize to go to full screen, so it doesn't trigger the SDL_WINDOWEVENT_RESIZED event, which is now triggered only on manually resizing a window. When we do move to SDL 2.0-only, I'll consolidate the logic appropriately to use SDL_WINDOWEVENT_SIZE_CHANGED. Thanks! |