We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2105

Summary: SDL_Window + glContext -> SDL_SetWindowDisplayMode() fails to resize the WM window.
Product: SDL Reporter: Yohann Ferreira <yohann.ferreira>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2 CC: bit.dangler
Version: 2.0.0   
Hardware: x86_64   
OS: Linux   
Attachments: The window doesn't resize leading to a gl context cut on top and on the right.

Description Yohann Ferreira 2013-09-19 00:40:21 UTC
Created attachment 1331 [details]
The window doesn't resize leading to a gl context cut on top and on the right.

Hi :)

When resizing the window using SDL_SetWindowDisplayMode(), the gl view port is correctly updated, but the window isn't. See attachment.

code in a nutshell:
// Window creation

SDL_Window *sdl_window = SDL_CreateWindow(APPFULLNAME,
                         SDL_WINDOWPOS_CENTERED,
                         SDL_WINDOWPOS_CENTERED,
                         800, 600, // default size
                         SDL_WINDOW_OPENGL);

SDL_GLContext glcontext = SDL_GL_CreateContext(sdl_window);

// ...

// changing the resolution
// After getting the closest possible available display mode
SDL_SetWindowDisplayMode(sdl_window, &dsp_mode);

-> See picture.

Best regards,
Comment 1 Yohann Ferreira 2013-09-19 00:40:46 UTC
This also applies on WinXP
Comment 2 bit.dangler 2013-11-04 20:14:52 UTC
From looking at your init flags, your window has not been set with the full-screen  flag and I suspect SDL_SetWindowDisplayMode() expects it to be in full-screen. If this suspicion is true then I will make it return a negative number and set a SDL error description.

I will investigate it in more depth at the weekend.
Comment 3 Yohann Ferreira 2013-11-05 09:40:29 UTC
Hi bit.dangler,

Thanks for your help on this!

"I suspect SDL_SetWindowDisplayMode() expects it to be in full-screen."
Is there any statement I could add in my code to test this suspicion?

Also, you can find the sdl2 branch of my code here:
https://github.com/Bertram25/ValyriaTear/tree/sdl2

You can find initial sdl window/context creation here:
https://github.com/Bertram25/ValyriaTear/blob/sdl2/src/main.cpp#L487

And resolution change code here:
https://github.com/Bertram25/ValyriaTear/blob/sdl2/src/engine/video/video.cpp#L375

I hope it'll help you.

Best regards,
Comment 4 bit.dangler 2013-11-05 16:18:58 UTC
(In reply to Yohann Ferreira from comment #3)
> Hi bit.dangler,
> 
> Thanks for your help on this!
> 
> "I suspect SDL_SetWindowDisplayMode() expects it to be in full-screen."
> Is there any statement I could add in my code to test this suspicion?

Tweak your SDL window initialization code so it adds the additional SDL_WINDOW_FULLSCREEN flag.

SDL_Window *sdl_window = SDL_CreateWindow(APPFULLNAME,
                         SDL_WINDOWPOS_CENTERED,
                         SDL_WINDOWPOS_CENTERED,
                         800, 600, // default size
                         SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);

Confirm your resize logic works when you put it in fullscreen mode. 

I think you need to call SDL_SetWindowSize() instead of calling SDL_SetWindowDisplayMode if you want to change the window's size when not in full-screen.

It should ideally return an error code when calling SDL_SetWindowDisplayMode when the window is not in full-screen. I will write a patch for this at the weekend.
Comment 5 Yohann Ferreira 2013-11-05 16:55:54 UTC
Hi again,

Ok, I'll make some tries and tell you.

> It should ideally return an error code when calling SDL_SetWindowDisplayMode 
> when the window is not in full-screen. I will write a patch for this at the 
> weekend.

Taken from the function description in the wiki:
"Use this function to set the display mode to use when a window is visible at fullscreen."
My bad, I guess my eyes (and brains) didn't get the fullscreen part. But then again, I'd say the function name is a bit misleading. (using the word "window" where you are handling fullscreen modes, but nevermind).

I'll also make tries using SDL_SetWindowSize in that case and see whether I can get something working.

Best regards!
Comment 6 Yohann Ferreira 2013-11-06 11:31:50 UTC
Hi again,

I confirm the SDL_SetWindowDisplayMode(sdl_window, &dsp_mode); is working in fullscreen mode for available display modes.

I might be overrating it but I find the function name SetWindowDisplayMode() misleading as it doesn't clearly tell about handling fullscreen modes only.
Just my two cents, though.

bit.dangler might also still be willing to patch the function to return an error code when not in fullscreen. Thanks for you help, btw. :)

I've also adjusted my code to use SDL_SetWindowSize() when not in fullscreen mode and it's working fine. :)
Thanks for all the support.

Best regards,
Comment 7 Sam Lantinga 2013-11-10 23:48:17 UTC
Great.  You're right it might be a little confusing.  I just fixed it so SetWindowSize() will always affect the windowed size, even if you're currently fullscreen.
Comment 8 Yohann Ferreira 2013-11-11 08:20:25 UTC
Thanks Sam. :)

I have one last request:
Could you add this sentence (or something like) in the remarks section there:
http://wiki.libsdl.org/SDL_SetWindowDisplayMode

"To change the display mode when not in full screen, use SDL_SetWindowSize()"

I bet this will make people like me realize one is not talking about actual windows here, but only fullscreen modes.

I won't blame you if you don't but it costs nothing asking. ;)

Best regards,
Comment 9 Sam Lantinga 2013-11-11 11:11:25 UTC
You got it. :)
Comment 10 Yohann Ferreira 2013-11-11 12:13:20 UTC
Great! thanks.