The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Couple of problems with fullscreen / window size /context
Smirftsch


Joined: 23 Jan 2016
Posts: 1
There are a couple of problems with my current SDL2 implementation, especially when it comes to fullscreen modes (OpenGL), Windows and Linux.

If I take the docs right this should be the way to resize a fullscreen window:

Code:

INT VideoFlags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_RESIZABLE;
if(RequestFullScreen)
{
   debugf(TEXT("SDL2: Requesting fullscreen"));
   if (0)
      VideoFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
   else VideoFlags |= SDL_WINDOW_FULLSCREEN;
}

if (RequestFullScreen)
{
   if (!IsFullScreen)
   {
      Result=SDL_SetWindowFullscreen(Window,VideoFlags);
      if (Result != 0)
         debugf( TEXT("SDL2: Couldn't switch into fullscreen mode (%ix%i): %s\n"), NewX, NewY,appFromAnsi(SDL_GetError()) );
      else debugf( TEXT("SDL2: Switched into fullscreen mode (%ix%i)"), NewX, NewY);
   }
   Result=SDL_SetWindowDisplayMode(Window, &NewMode);
   if (Result != 0)
      debugf( TEXT("SDL2: Couldn't set resolution of (%ix%i): %s\n"), NewX, NewY,appFromAnsi(SDL_GetError()) );
   else debugf( TEXT("SDL2: Set resolution of (%ix%i)"), NewX, NewY );
}


I also intend to make use of SDL_WINDOW_FULLSCREEN_DESKTOP because I am aware about the problems with fullscreen resolution changes, especially in Linux. Still I think a game needs the ability to change the resolution, so this would be nice if it would be working. Current problem with that is, that the resolution is virtually changed, so its running at requested resolution (like 1920x1080) but the real screen solution is unchanged like 1440x1050, in other words, I am only getting a virtual resolution of 1920 (I hope you know what I mean). To combine it with SDL_SetWindowSize didn't make any visible difference as well.


To change windowed size I am doing the following:
Code:

if (IsFullScreen)
{
   Result=SDL_SetWindowFullscreen(Window,0);
   if (Result != 0)
      debugf( TEXT("SDL2: Couldn't switch into windowed mode (%ix%i): %s\n"), NewX, NewY,appFromAnsi(SDL_GetError()) );
   else debugf( TEXT("SDL2: Switched into windowed mode (%ix%i): %s\n"), NewX, NewY,appFromAnsi(SDL_GetError()) );
}
SDL_SetWindowSize(Window,NewX,NewY);
debugf( TEXT("SDL2: Switched windowed mode to (%ix%i): %s\n"), NewX, NewY );


It changes the window size, but it doesn't resize the window. I am getting a window inside the previous window, so if I switch from lets say 1280x1024 to 1024x768 I am getting a 1024 window inside the former frame of 1280.
The code above is what I think the docs say how it works, but I changed this maybe a dozen of times already in various orders and variations without a single successful result.

Now I read about that SDL2 is having a couple of fullscreen problems, so I tried at first to update from 2.0.3 which I was still running to 2.0.4 stable.
However, in Linux 2.0.4 fails to create an OpenGL context entirely with 2.0.4 and in Windows I am still getting a context, but the resolution changes are not working anyway.

context creation looks like this currently:

Code:


if (SDL_GL_LoadLibrary(NULL) == -1)
{
   appErrorf(TEXT("SDL_GL_LoadLibrary failed: %s"),appFromAnsi(SDL_GetError()));
}


SDL_GL_SetAttribute(SDL_GL_RED_SIZE, (NewColorBytes <= 2) ? 5 : 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, (NewColorBytes <= 2) ? 5 : 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, (NewColorBytes <= 2) ? 5 : 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, DesiredDepthBits);

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, MajorVersion);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, MinorVersion);
#ifdef GLES
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#else
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif

SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, DesiredColorBits);

if (UseOpenGLDebug)
   SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);

glContext = SDL_GL_CreateContext(Window);

if (glContext == NULL)
   appErrorf(TEXT("Error: SDL_GL_CreateContext %s"),appFromAnsi(SDL_GetError()));

glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
   appErrorf(TEXT("Error: Init glew failed: %s"), appFromAnsi((char*)glewGetErrorString(err)));
else debugf(NAME_Init, TEXT("Glew successfully initialized."));


As said, this works in Linux (OpenSuSE13.2 currently) with 2.0.3 flawlessly in 2.0.4 it fails creating a context. Doesn't matter if taking a prebuild package or building myself. Also tried various combinations and versions of context creation without any success.

When I switched to 2.0.4 latest dev version from mercurial it fails to init video mode directly, not even coming so far to fail with context creation.

Additionally to all these problems gamma settings fail entirely with
Quote:
Window doesn't have DirectColor visual
when trying to use SDL_SetWindowGammaRamp(Window, Ramp.red, Ramp.green, Ramp.blue ); and this code was working on some point definitely too with an older release (unfortunately didn't keep the old stuff, so can't say exactly which version).

Any advice to the above problems is welcome.