3

My program starts with a loading window while it is compiling shaders, loading textures etc. I then want to be able to launch a fullscreen application and use these resources. My understanding is that the openGL context must be the same before and after. I tried two methods for this: first of all I tried making a second window which was fullscreen, and used the SDL_GL_makecurrent command on this window to 'transfer' the context across (couldn't find where I read about this method), and secondly tried just fullscreening the loading window. Both of these methods resulted in the loading screen being moved to the top left corner of the screen. However opengl commands no longer ran properly in fullscreen, including clearing buffers which meant that the window contained the contents of my desktop/background applications.

Is there a proper way of doing this? Or is this a strange bug in sdl/opengl drivers?

Code to fullscreen original window:

//opengl commands work fine up to here
//now to fullscreen

SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetWindowSize(window, 1366, 768); //tried this on either side of line above and without either line

glViewport(0, 0, 1366, 768); //update viewport

glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT);

//window should be whited, other draw commands tried and all fail or distort

SDL_GL_SwapWindow(window);

Creating a new window and using previous context:

//Fine up to here

window2 = SDL_CreateWindow("Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1366, 768, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_SHOWN);

SDL_GL_MakeCurrent(window2, glContext); //created with SDL_GL_CreateContext(oldwindow);

//draw commands dont work

PS: running ubuntu

Update: In the second code, reusing the context in a new window, it returns an error saying 'invalid window' when it fails, which is most of the time but not always. When it fails, the screen ends up completely corrupted(black with weird white squares and patterns), ending the program will not clear the screen of this (although screenshots are perfectly fine?), but it can be restored by ctrl+f1 to terminal then ctrl+f7 back

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

I dont really know if its a bug. I experienced the same issue with sdl2 and opengl.

  • Create an regular window
  • attach to opengl context.
  • fullscreen
  • BOOM. black screen and crashed window.

I only noticed that issue in ubuntu.

Trought some tests i found a quick way to fix it:

Uint32 flags = 0; 
flags |= SDL_WINDOW_RESIZABLE;
//bla bla bla your tags
flags |= SDL_WINDOW_OPENGL;   
m_window = SDL_CreateWindow( "hello gl", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_screen.x, m_screen.y,flags);
m_glContext = SDL_GL_CreateContext(m_window);
//Set right the way the screen to fullscrene false
SDL_SetWindowFullscreen(m_window, SDL_FALSE);

Now the fullscreen seems to work without problem.