gpt4 book ai didi

c - wgl使当前纹理消失

转载 作者:行者123 更新时间:2023-11-30 20:30:19 26 4
gpt4 key购买 nike

您好,我正在尝试在不同的显示器上渲染 3 个全屏窗口,到目前为止,我已成功查询现有显示器 EnumDisplayMonitors 以获取使用 创建 3 个窗口所需的 4 个参数应用 WS_POPUP 样式。

在一帧中我执行以下操作:

for(int i=0; i<monitorsNum; i++)
{
wglMakeCurrent(hdcs[i], sharedHrc);
doRendering();
SwapBuffers(hdcs[i]);
}

许多网站都提出了相同的建议,但是,当我从 1 个显示器切换到 2 个或更多显示器时,纹理消失了:

enter image description here

您看到的是同一场景渲染了 3 次,背景透明颜色略有不同表明至少我所做的事情部分正确(gl 透明颜色显示正确,它甚至适用于 3 个不同尺寸的 3 个显示器) 。我尝试使用 glGetError() 拦截所有 gl 调用,但没有收到任何错误。是否有我错过的特定步骤,或者可能是我的笔记本电脑的问题?

如果有帮助的话,这 3 个窗口是使用现有框架创建的,因此在创建时每个窗口都被赋予了自己的 hrc,但随后我只为其他 2 个窗口使用一个 hrc。 (所以创建 3 小时,使用 1 小时,如果重要的话)

最佳答案

渲染某些几何体时纹理可能无法正确显示的原因有很多。

但假设您的问题与这些问题无关,例如不正确的 UVS、着色器问题、纹理创建等,则该问题可能与您现在管理多个上下文这一事实有关。

要设置多个窗口,您需要为每个窗口创建一个上下文。wglMakeCurrent 函数允许您切换每个窗口的上下文,并随时进行渲染。

https://learn.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-wglmakecurrent

The wglMakeCurrent function makes a specified OpenGL rendering context the calling thread's current rendering context. All subsequent OpenGL calls made by the thread are drawn on the device identified by hdc. You can also use wglMakeCurrent to change the calling thread's current rendering context so it's no longer current.

OpenGL 上下文代表默认帧缓冲区(渲染时着色器将输出到的默认位置),但它还存储与该 OpenGL 实例关联的所有状态。

此外:

Each context has its own set of OpenGL Objects, which are independent of those from other contexts.

因此,这意味着除非明确告知,否则每个上下文都无法访问相同的资源。

Any object sharing must be made explicitly, either as the context is created or before a newly created context creates any objects. However, contexts do not have to share objects; they can remain completely separate from one another.

因此,您能够在每个窗口中渲染相同纹理的原因之一是该纹理不是共享资源。 glClearColor 工作正常,因为它不依赖于与任何特定上下文关联的任何资源。

关于c - wgl使当前纹理消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54523350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com