是否可以在主渲染循环之外渲染到帧缓冲区对象

发布于 2024-10-01 04:50:46 字数 431 浏览 0 评论 0原文

我正在使用一个单独的帧缓冲区对象来在 opengl 中拾取 2d 对象的颜色。我很好奇是否可以只绘制到帧缓冲区并在需要时读取颜色。

我现在正在做的是在主渲染循环中,我将场景绘制到主帧缓冲区,然后仅将可选对象渲染到“拾取”帧缓冲区。

当用户单击鼠标时,它会绑定“拾取”帧缓冲区并读取像素,我知道选择了哪个对象。这样做的问题是,当用户单击鼠标时,我只需要“拾取”帧缓冲区,因此每一帧都这样做效率低下。

我尝试在用户单击鼠标时渲染到“拾取”帧缓冲区,然后直接读取,但我得到的只是白色(背景颜色,而不是告诉我它是什么对象的颜色)。绘制“拾取”帧缓冲区只会将整个事物显示为白色,就像实际上根本没有渲染任何东西一样。

我是否需要在渲染到“拾取”帧缓冲区时停止在主循环中绘制?还是我缺少一些东西可以使这成为可能?

编辑:我尝试在渲染到拾取帧缓冲区时不在主循环中绘制,但这也不起作用。

i am using a separate framebuffer object for color picking 2d objects in opengl. i am curious if its possible to only draw to the framebuffer and read the color when needed.

what i am doing now is in the main render loop i draw the scene to the main framebuffer and then render just the selectable objects to the "picking" framebuffer.

when the user clicks the mouse it binds the "picking" framebuffer and reads the pixel and i know which object is selected. the problem with this is i only need the "picking" framebuffer when a user clicks the mouse so doing this every frame is inefficient.

i have tried rendering to the "picking" framebuffer when the user clicks the mouse and then reading directly but all i get is white (the background color and not the color to tell me which object it is). drawing the "picking" framebuffer just shows the entire thing as white like nothing was actually rendered to it at all.

do i need to stop drawing in the main loop while rendering to the "picking" framebuffer? or is there something im missing that would make this possible?

EDIT: i have tried not drawing in the main loop while rendering to the picking framebuffer and that did not work either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿! 2024-10-08 04:50:46

您需要检查是否使用 wglMakeCurrentglXMakeCurrent 将 GL 上下文设置为当前上下文。此外,它必须在同一个线程中完成,因为只有一个线程可以拥有当前上下文。

You need to check that you made your GL context the current one using either wglMakeCurrent or glXMakeCurrent. Also, it has to be done in the same thread, since only one thread can have a current context.

寄风 2024-10-08 04:50:46

“不”。

但您可以使用多个 GPU(如果有的话)。 此处此处 org/registry/specs/AMD/wgl_gpu_association.txt" rel="nofollow">在这里您可以找到 OpenGL 规范;驱动程序必须支持 *WGL_NV_gpu_affinity* 或 *AMD_gpu_association* 扩展。

"No".

But you can multiple GPUs (if you have it). Here or here you can find the OpenGL specification; the driver must support *WGL_NV_gpu_affinity* or *AMD_gpu_association* extension.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文