Recreate Window without destroying the Context

落爺英雄遲暮 提交于 2019-12-12 09:00:00

问题


This question is about a graphics application using OpenGL. (At the time I am using the framework GLFW but I consider changing it.)

My aim is to let the user (as much as possible) continuously switch between fullscreen mode and windowed mode. This procedure should take less than a second and can occur during runtime. For example see the game Minecraft where the user can toggle fullscreen with virtually no delay.

The window recreation process doesn't take so much time. But the problem is, that closing the window destroys my OpenGL context and I have to reload all my shaders and buffers.

How to recreate the window of a graphics application without destroying the OpenGL context? (I would like to use GLFW but I am open minded about alternative frameworks or a own implementation.)


回答1:


Technically the OpenGL context is not tied to any window. What's important is, that the visual format of the window matches that of the visual format the context has been created for. It is perfectly possible to use a single OpenGL context with multiple windows.

The problem you're facing is, that frameworks like GLFW, SDL or GLUT don't expose this kind of functionality. It's a feature that definitely should be added to them some time.

You can however do it, when you create and manage your windows and OpenGL context yourself. The principal process of what you intend is the following:

  1. select the visual format for the windows (PIXELFORMATDESCRIPTOR, Visual, FBConfig, depending on OS and graphics system)

  2. create your first window and set the visual format

  3. create the OpenGL context with respect to the first window as drawable

  4. create further windows and set them to the very same visual format you've already selected.

You can now detach the OpenGL context from its current drawable (=window) and attach it to any other drawable (i.e. window) having a compatible visual format



来源:https://stackoverflow.com/questions/12881049/recreate-window-without-destroying-the-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!