Hello,
I’ve tried to toggle between fullscreen and windowed mode, but calling [icode]glfwDestroyWindow()[/icode] also destroys it’s context. Is there any way to toggle between fullscreen and windowed mode without losing the context?
Thanks.
Hello,
I’ve tried to toggle between fullscreen and windowed mode, but calling [icode]glfwDestroyWindow()[/icode] also destroys it’s context. Is there any way to toggle between fullscreen and windowed mode without losing the context?
Thanks.
See this issue. Looks like it will be supported in GLFW 3.2.
In the meantime, you can use context sharing to save your GL objects during a mode switch. Something like:
long newWindow = glfwCreateWindow(w, h, title, glfwGetPrimaryMonitor(), window);
glfwDestroyWindow(window);
window = newWindow;
// setup new window (callbacks, make context current and init GL state, etc)
This way all your shaders, buffer objects and textures will survive the switch. The drawback is that you’ll have to recreate the OpenGL state to what it was. This is usually not a problem because the switch will never happen mid-frame.
Thanks for your reply Spasi. This is resolved for now. For anybody who is having this issue, here is my [icode]setFullScreen()[/icode] method.
public static void setFullScreen(boolean fullScreen)
{
if (Display.fullScreen == fullScreen)
return;
Display.fullScreen = fullScreen;
if (fullScreen)
{
ByteBuffer vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
oldWidth = width;
oldHeight = height;
width = GLFWvidmode.width(vidMode);
height = GLFWvidmode.height(vidMode);
}
else
{
width = oldWidth;
height = oldHeight;
}
// Create new window
long fsDisplayHandle = glfwCreateWindow(width, height, "SilenceEngine", fullScreen ? glfwGetPrimaryMonitor() : NULL, displayHandle);
glfwDestroyWindow(displayHandle);
displayHandle = fsDisplayHandle;
glfwMakeContextCurrent(displayHandle);
glfwSwapInterval(1);
GLContext.createFromCurrent();
glClear(GL_COLOR_BUFFER_BIT);
resized = true;
WindowCallback.set(displayHandle, new WindowCallbackAdapter()
{
@Override
public void windowSize(long window, int width, int height)
{
Display.width = width;
Display.height = height;
resized = true;
}
@Override
public void key(long window, int key, int scanCode, int action, int mods)
{
}
});
show();
centerOnScreen();
}
Yes, I’m trying to make a Display class, so that most of the old code can be ported without many problems. Thanks again Spasi.