重新创建窗口而不破坏上下文 [英] Recreate Window without destroying the Context

查看:183
本文介绍了重新创建窗口而不破坏上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是关于使用OpenGL的图形应用程序。 (当时我正在使用框架GLFW,但我考虑改变它)。

我的目标是让用户(尽可能)在全屏模式和窗口模式。此过程应该不到一秒钟,并且可能在运行时发生。例如,看看游戏Minecraft,用户可以毫不拖延地切换全屏。



窗口重新创建过程不需要太多时间。但问题是,关闭窗口会破坏我的OpenGL上下文,我必须重新加载所有着色器和缓冲区。



如何重新创建图形窗口应用程序不破坏OpenGL上下文吗?(我想使用GLFW,但是我对开放式的框架或自己的实现是开放的。)

解决方案

从技术上讲,OpenGL上下文并不依赖于任何窗口。重要的是,窗口的可视格式与创建上下文的可视格式相匹配。这是完全可能的,使用单个OpenGL上下文与多个窗口。



您面临的问题是,像GLFW,SDL或GLUT的框架不公开此一种功能。这是一个肯定应该添加到它们的功能。



然而,当你自己创建和管理你的窗口和OpenGL上下文时,你可以做到这一点。你打算做什么的主要过程如下:


  1. 选择窗口的可视格式(PIXELFORMATDESCRIPTOR,Visual,FBConfig,取决于操作系统和图形系统)

  2. 创建您的第一个窗口并设置可视格式


  3. 创建与第一个窗口相关的OpenGL上下文作为可绘制的

  4. 创建更多的窗口并将它们设置为您已经选择的相同视觉格式。


现在,您可以将OpenGL上下文从当前可绘制窗口(= window)中分离出来,并将其附加到任何其他可绘制即窗口)具有兼容的视觉格式

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.)

解决方案

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

这篇关于重新创建窗口而不破坏上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆