SDL_SetWindowFullscreen fails to set window to fullscreen mo

What is the current status of this with SDL 1.3?

I’m running with Win32, and it does switch to full screen and back again, but the fullscreen display mode and position leaves something to be desired. It’s not clear to me from the source code whether I should be doing something about size and position or whether that is work that remains to be done.

I could use some guidance here.

Walt

Going fullscreen works on Windows and Mac OS X, but if you’re
specifying a mode that isn’t one of the available video modes, it
doesn’t properly center the display yet.

See ya!On Wed, Dec 23, 2009 at 11:26 AM, WaltN wrote:

What is the current status of this with SDL 1.3?

I’m running with Win32, and it does switch to full screen and back again,
but the fullscreen display mode and position leaves something to be desired.
It’s not clear to me from the source code whether I should be doing
something about size and position or whether that is work that remains to be
done.

I could use some guidance here.

Walt


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

What I’m experiencing (with Windows Vista and SVN 5431) is that I have to set the window size following an SDL_SetWindowFullscreen in order to get a window of the proper size.

And, just to make sure we’re on the same wavelength, what I get following an SDL_SetWindowFullscreen is a correct change of the Desktop display mode. The SDL window has a border and it needs to be resized and positioned in order to “fool” a user into seeing fullscreen mode.

In my case fullscreen on Windows starts correctly only with “d3d” renderer selected. For “gdi” or “opengl” window has correct size but is not correctly positioned.

I thought it might be worthwhile for me to post fragments of my code. First, here is my default window creation:

Code:
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;

window=SDL_CreateWindow(“GLTest3[__cdecl]”,
lastWindowedPosSize.x, lastWindowedPosSize.y, lastWindowedPosSize.w, lastWindowedPosSize.h,
flags);

Desired fullscreen characteristics:

Code:
// Make fullscreen mode same as Desktop
SDL_GetDesktopDisplayMode(&fsmode);
SDL_SetWindowDisplayMode(window, &fsmode); // Set fullscreen mode characteristics

When I want to switch to fullscreen mode:

Code:
SDL_SetWindowFullscreen(windowID, 1); // Go to fullscreen mode

The fullscreen characteristics I get are a window with a resizeable border, and whose position is way off. I work around this by setting the size and position AFTER the call to SDL_SetWindow DisplayMode. But, the window I get is never a real borderless fullscreen window. (This with Vista.)

It would be nice to have an example of code that works with the desired behavior.

The fullscreen characteristics I get are a window with a resizeable border, and whose position is way off. I work around this by setting the size and position AFTER the call to SDL_SetWindow DisplayMode. But, the window I get is never a real borderless fullscreen window. (This with Vista.)

It would be nice to have an example of code that works with the desired behavior.

I also cannot get fullscreen mode to work with SDL 1.3. I wrote a
stripped down program which you can see below.

This program starts up in windowed mode. If I press F1 to go
fullscreen, nothing happens. But if I then move the mouse outside the
window, it disappears and the program is still running. Creating the
window with SDL_WINDOW_FULLSCREEN gives me a borderless window of the
size specified (it does not fill the screen) that does not accept
keyboard input.

Is there something I’m missing? I haven’t found much sample code for
windowing with 1.3, so this is the best I’ve come up with so far.–
Terry Welsh / mogumbo ‘at’ gmail.com
www.reallyslick.com / www.mogumbo.com

#include <SDL.h>
#include
#include <GL/gl.h>

#define SDL_NO_COMPAT

using namespace std;

static bool gQuit(false);
static SDL_WindowID gWindow;
static SDL_GLContext gGLContext;

int gWinW = 640;
int gWinH = 480;
bool gFullscreen = false;

void resize(int w, int h){
if(gFullscreen)
SDL_SetWindowFullscreen(gWindow, 1);
else{
SDL_SetWindowFullscreen(gWindow, 0);
SDL_SetWindowSize(gWindow, w, h);
gWinW = w;
gWinH = h;
}

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glOrtho(-1,1,-1,1,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

void toggleFullscreen(){
gFullscreen = !gFullscreen;
resize(gWinW, gWinH);
cout << "fullscreen = " << int(gFullscreen) << endl;
}

void processEvents(){
SDL_Event event;
while(SDL_PollEvent(&event)){
switch(event.type){
case SDL_WINDOWEVENT:
switch(event.window.event){
case SDL_WINDOWEVENT_RESIZED:
resize(event.window.data1, event.window.data2);
break;
}
break;
case SDL_QUIT:
gQuit = true;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym){
case SDLK_ESCAPE:
gQuit = true;
break;
case SDLK_F1:
toggleFullscreen();
break;
}
break;
}
}
}

int main(int argc, char* argv[]){
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0){
cout << "Unable to init SDL: " << SDL_GetError() << endl;
exit(1);
}
atexit(SDL_Quit);

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
gWindow = SDL_CreateWindow("Retrobooster", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED, gWinW, gWinH, SDL_WINDOW_OPENGL |
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
gGLContext = SDL_GL_CreateContext(gWindow);
SDL_GL_SetSwapInterval(1); // v-sync on

resize(gWinW, gWinH);

while(!gQuit){
	processEvents();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glColor4f(1,1,1,1);
	glBegin(GL_TRIANGLE_STRIP);
		glVertex3f(-0.5f, -0.5f, 0.0f);
		glVertex3f(0.5f, -0.5f, 0.0f);
		glVertex3f(0.5f, 0.5f, 0.0f);
	glEnd();

	SDL_GL_SwapWindow(gWindow);
}

SDL_GL_DeleteContext(gGLContext);
SDL_DestroyWindow(gWindow);

return 1;

}

This program starts up in windowed mode. If I press F1 to go
fullscreen, nothing happens.
When I build my code (above) without specifying an SDL_DisplayMode structure (as I believe you have done), SDL 1.3 is supposed to select a default display mode. When I do this, I don’t get nothing. Rather, I get what looks to be 640x480 and a poorly positioned SDL window with a border.

You might try specifying an SDL_DisplayMode structure either as I have (Desktop mode) or explicitly (e.g., pixel format of SDL_RGB888). Also, I’ve seen statements that suggest playing with depth buffer size (16, 24, 32).

Thanks for the ideas Walt. No luck, though. I added this during
initialization:

SDL_DisplayMode fsmode;
SDL_GetDesktopDisplayMode(&fsmode);
cout << fsmode.format << " " << fsmode.w << " " << fsmode.h << " " <<
fsmode.refresh_rate << " " << int(fsmode.driverdata) << endl;
cout << "SDL_SetWindowDisplayMode = " <<
SDL_SetWindowDisplayMode(gWindow, &fsmode) << endl;

The output I get is this:

2249594884 1920 1200 0 0
SDL_SetWindowDisplayMode = 0

Looks like my format was already set to SDL_PIXELFORMAT_RGB888.–
Terry Welsh / mogumbo ‘at’ gmail.com
www.reallyslick.com / www.mogumbo.com

Message: 1
Date: Wed, 20 Jan 2010 08:09:50 -0800
From: “WaltN”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_SetWindowFullscreen fails to set window to
fullscreen mo
Message-ID: <1264003790.m2f.21892 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

This program starts up in windowed mode. If I press F1 to go
fullscreen, nothing happens.
When I build my code (above) without specifying an SDL_DisplayMode structure (as I believe you have done), SDL 1.3 is supposed to select a default display mode. When I do this, I don’t get nothing. Rather, I get what looks to be 640x480 and a poorly positioned SDL window with a border.

You might try specifying an SDL_DisplayMode structure either as I have (Desktop mode) or explicitly (e.g., pixel format of SDL_RGB888). Also, I’ve seen statements that suggest playing with depth buffer size (16, 24, 32).

I could be wrong, but shouldn’t SDL_NO_COMPAT be defined before including <SDL.h> ? A quick search indicates this is the case.On 01/19/2010 06:53 PM, Terry Welsh wrote:

#include <SDL.h>
#include
#include <GL/gl.h>

#define SDL_NO_COMPAT


Forest ‘LordHavoc’ Hale
Author of DarkPlaces Quake1 engine and mod
http://icculus.org/twilight/darkplaces
Address: 94340 Horton Road Blachly OR 97412
Phone/Fax: 541-925-4130

In my case, #define SDL_NO_COMPAT doesn’t make any difference. When I don’t set size and position following a toggle to fullscreen, I get the same result as Terry Welsh – no apparent effect. But, if I include setting size and position, the window is still bordered and resizeable. If I accept the default fullscreen mode, I get what looks like a 640x480 bordered window badly placed on a 640x480 desktop.

I get the feeling we’re doing something basic that is dead wrong; hence the plea for sample code of the correct way to get the correct behavior.

That’s correct, I have SDL_NO_COMPAT in the wrong place. I’ll switch
it when I get home tonight but it shouldn’t make any difference. The
code I sent was stripped down from my game code where SDL_NO_COMPAT is
part of the makefile. I just got it in the wrong order when I
stripped it down.

I tried stepping through the code to compare the SDL_compat path with
my new 1.3-based code. Unfortunately, ddd wasn’t cooperating and
skipping around a lot (reminded me of debugging in VS). Anyway, as
best I can tell in the SDL_compat path the window is destroyed and
created again as a fullscreen window, a behavior I couldn’t manage to
mimic properly. My new 1.3-based path goes through the
SDL_SetWindowFullscreen() but never seems to do any of the necessary
things I’d expect, such as calling SDL_SetWindowPosition() and
SDL_SetWindowSize(). Maybe that code is just unfinished.

Still stumped. I’ll probably try harder to mimic what SDL_compat
does. I can’t think of anything else to try without a good example
program or documentation that says how to go fullscreen.–
Terry


Message: 9
Date: Thu, 21 Jan 2010 05:54:09 -0800
From: “WaltN”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_SetWindowFullscreen fails to set window to
? ? ? ?fullscreen ? ? ?mo
Message-ID: <1264082049.m2f.21918 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

In my case, #define SDL_NO_COMPAT doesn’t make any difference. ?When I don’t set size and position following a toggle to fullscreen, I get the same result as Terry Welsh – no apparent effect. ?But, if I include setting size and position, the window is still bordered and resizeable. ?If I accept the default fullscreen mode, I get what looks like a 640x480 bordered window badly placed on a 640x480 desktop.

I get the feeling we’re doing something basic that is dead wrong; hence the plea for sample code of the correct way to get the correct behavior.

Terry, I don’t think our problem has anything to do with 1.2 compatibility. Except for not seeing any change when fullscreen mode = Desktop mode, I really don’t see any difference in behavior with other modes. On inspection, I really don’t think that either of us is using any 1.2 functionality. Strangely, with Visual C++ 2009 Express, when I define SDL_NO_COMPAT, I loose Intellisense knowledge of almost all SDL names. And yet the program builds successfully. Given that, I don’t view SDL_NO_COMPAT as helpful. (I suppose it could be a VC++ bug or even due to my ignorance.)

Anyway, as
best I can tell in the SDL_compat path the window is destroyed and
created again as a fullscreen window, a behavior I couldn’t manage to
mimic properly.

How can you tell? I’ve verified that the SDL_WINDOW_FULLSCREEN flag is getting set, but RESIZEABLE remains set. (OPENGL, SHOWN, INPUT_FOCUS, and MOUSE_FOCUS also set). I have not tried to verify whether the “real” window flags are getting altered. Certainly the display mode is changing if I request a size different from the Desktop mode. But, I see no signs of the window being destroyed and created.

I believe that I’m getting a legitimate fullscreen window in that the window will cover up the Windows Taskbar. The shortcoming is that it’s bordered and resizeable, and it’s positioned badly.

Hi Walt,
I think I was unclear in my previous post. The reason I was comparing
the 1.3-based version of my code to my SDL_compat version is because
in the compat version my window successfully goes fullscreen.
…well, almost successfully; I still have this input problem in
Linux: http://lists.libsdl.org/pipermail/sdl-libsdl.org/2009-December/073848.html

But the important part is that I do get a fullscreen Window, so I
figured the SDL_compat code should hold a good method for doing
fullscreen windows. Although, destroying the old window and creating
a new one seems heavy-handed to me if that’s what’s actually going on
(still need more time to examine what’s going on).–
Terry Welsh / mogumbo ‘at’ gmail.com
www.reallyslick.com / www.mogumbo.com

Message: 1
Date: Thu, 21 Jan 2010 11:44:10 -0800
From: “WaltN”
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_SetWindowFullscreen fails to set window to
? ? ? ?fullscreen ? ? ?mo
Message-ID: <1264103050.m2f.21932 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

Terry, I don’t think our problem has anything to do with 1.2 compatibility. ?Except for not seeing any change when fullscreen mode = Desktop mode, I really don’t see any difference in behavior with other modes. ?On inspection, I really don’t think that either of us is using any 1.2 functionality. ?Strangely, with Visual C++ 2009 Express, when I define SDL_NO_COMPAT, I loose Intellisense knowledge of almost all SDL names. ?And yet the program builds successfully. ?Given that, I don’t view SDL_NO_COMPAT as helpful. ?(I suppose it could be a VC++ bug or even due to my ignorance.)

Anyway, as
best I can tell in the SDL_compat path the window is destroyed and
created again as a fullscreen window, a behavior I couldn’t manage to
mimic properly.

How can you tell? ?I’ve verified that the SDL_WINDOW_FULLSCREEN flag is getting set, but RESIZEABLE remains set. (OPENGL, SHOWN, INPUT_FOCUS, and MOUSE_FOCUS also set). ?I have not tried to verify whether the “real” window flags are getting altered. ?Certainly the display mode is changing if I request a size different from the Desktop mode. ?But, I see no signs of the window being destroyed and created.

I believe that I’m getting a legitimate fullscreen window in that the window will cover up the Windows Taskbar. ?The shortcoming is that it’s bordered and resizeable, and it’s positioned badly.

I think I ran into the same issue as you…; I couldn’t switch to fullscreen from windowed. Specifically, I was creating a non-shown window first so that I could select the display mode with SDL_SetWindowDisplayMode (I couldn’t find a better way – and the ability to select refresh rate through the display mode is the reason that I am using SDL 1.3), and following it up with a call to SDL_SetWindowFullscreen.

I debugged it a bit and I think I found the main issue… I didn’t read the thread in detail, but I imagine you might have found it too. The display’s num_windows member never got incremented on creation of a window (and also never gets decremented on killing of a window). Rather than risk missing places where it should be incremented or decremented, I added this simple function to work around the issue…:

int
SDL_GetNumWindowsForDisplay(SDL_VideoDisplay * display)
{
/* Count the windows associated with this display */
int num_windows = 0;
SDL_Window *cur_window = display->windows;
while (cur_window)
{
num_windows++;
cur_window = cur_window->next;
}
return num_windows;
}

… and I removed num_windows from the SDL_VideoDisplay struct. This allows it to transition to fullscreen and back.

This should be fixed in revision 5544, thanks!On Sat, Jan 30, 2010 at 7:33 PM, augzilla wrote:

I think I ran into the same issue as you…; I couldn’t switch to fullscreen
from windowed. Specifically, I was creating a non-shown window first so that
I could select the display mode with SDL_SetWindowDisplayMode (I couldn’t
find a better way – and the ability to select refresh rate through the
display mode is the reason that I am using SDL 1.3), and following it up
with a call to SDL_SetWindowFullscreen.

I debugged it a bit and I think I found the main issue… I didn’t read the
thread in detail, but I imagine you might have found it too. The display’s
num_windows member never got incremented on creation of a window (and also
never gets decremented on killing of a window). Rather than risk missing
places where it should be incremented or decremented, I added this simple
function to work around the issue…:

int
SDL_GetNumWindowsForDisplay(SDL_VideoDisplay * display)
{
/* Count the windows associated with this display */
int num_windows = 0;
SDL_Window *cur_window = display->windows;
while (cur_window)
{
num_windows++;
cur_window = cur_window->next;
}
return num_windows;
}

… and I removed num_windows from the SDL_VideoDisplay struct. This allows
it to transition to fullscreen and back.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Unfortunately, rev 5544 didn’t change anything for me. Maybe I have a
different problem. My window still doesn’t go fullscreen when
commanded to and then disappears if I move the mouse out of it. I
took a good hard look at the video code a couple weeks ago and
couldn’t figure out where the problem was. Hopefully I’ll get to look
at it again soon.–
Terry

Message: 3
Date: Sun, 31 Jan 2010 17:19:17 -0800
From: Sam Lantinga
To: sdl at lists.libsdl.org
Subject: Re: [SDL] SDL_SetWindowFullscreen fails to set window to
? ? ? ?fullscreen ? ? ?mo
Message-ID:
? ? ? ?<3adffa61001311719k4a5769a2x945f2e09d1b0883f at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

This should be fixed in revision 5544, thanks!

On Sat, Jan 30, 2010 at 7:33 PM, augzilla wrote:

I think I ran into the same issue as you…; I couldn’t switch to fullscreen
from windowed. Specifically, I was creating a non-shown window first so that
I could select the display mode with SDL_SetWindowDisplayMode (I couldn’t
find a better way – and the ability to select refresh rate through the
display mode is the reason that I am using SDL 1.3), and following it up
with a call to SDL_SetWindowFullscreen.

I debugged it a bit and I think I found the main issue… I didn’t read the
thread in detail, but I imagine you might have found it too. The display’s
num_windows member never got incremented on creation of a window (and also
never gets decremented on killing of a window). Rather than risk missing
places where it should be incremented or decremented, I added this simple
function to work around the issue…:

int
SDL_GetNumWindowsForDisplay(SDL_VideoDisplay * display)
{
/* Count the windows associated with this display */
int num_windows = 0;
SDL_Window *cur_window = display->windows;
while (cur_window)
{
num_windows++;
cur_window = cur_window->next;
}
return num_windows;
}

… and I removed num_windows from the SDL_VideoDisplay struct. This allows
it to transition to fullscreen and back.

having exactly the same problem at rev 5549.

compiled the tests and I get the exact same result when i use --fullscreen on the testgl2.exe.