OpenGL 与 MFC

发布于 2024-12-10 14:49:04 字数 377 浏览 0 评论 0原文

我正在尝试在 CSplitterWnd 内创建 4 个 OpenGL 视口,但遇到了一些问题。

起初,我遇到了闪烁和绘图问题,直到我将 PFD_SUPPORT_GDI 标志添加到像素格式中,这使得一切都能很好地协同工作。但是当我使用 PFD_SUPPORT_GDI 时,我只能获得 1.1 OpenGL 上下文。

是否可以将 PFD_SUPPORT_GDI 与高于 1.1 的 OpenGL 版本一起使用,以便我可以使用 VBO?还是有另一种方法可以让 OpenGL 在没有 PFD_SUPPORT_GDI 的情况下正常工作?

没有 PFD_SUPPORT_GDI 的最大问题是,当您拖动分割器窗口分隔符时,它会擦除​​视口内容。使用 PFD_SUPPORT_GDI 标志时不会发生这种情况。

I am trying to make 4 OpenGL viewports inside a CSplitterWnd, but am having some problems.

At first, I had flickering and drawing issues until I added the flag PFD_SUPPORT_GDI into the pixel format, which made everything work nicely together. But when I use PFD_SUPPORT_GDI, I am only able to get a 1.1 OpenGL context.

Is it possible to use PFD_SUPPORT_GDI with a version of OpenGL higher than 1.1 so that I can use VBOs? or is there another way to get OpenGL to work properly without PFD_SUPPORT_GDI?

The biggest problem with not having PFD_SUPPORT_GDI is that the splitter window separator wipes the viewport contents away when you drag over it..which does not happen while using the PFD_SUPPORT_GDI flag.

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

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

发布评论

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

评论(3

野侃 2024-12-17 14:49:04

PFD_SUPPORT_GDI 意味着,您希望能够使用 GDI 调用进行绘制,这将迫使您使用软件渲染器。

大多数情况下,闪烁问题(尤其是 MFC)是由于未正确设置/选择 WNDCLASS(EX) 参数造成的。最重要的是,应设置 CS_OWNDC 标志,并且背景画笔应为 NULL。此外,您还应该覆盖 OnEraseBackground 处理程序并实现 OnPaint 处理程序,该处理程序报告经过验证的矩形。

PFD_SUPPORT_GDI means, you want to be able to draw using GDI calls, which will force you into using the software renderer.

Most of the time flicker issues, especially with MFC are due to not properly set/choosen WNDCLASS(EX) parameters. Most importantly CS_OWNDC flag should be set and the background brush should be NULL. Also you should overwrite the OnEraseBackground handler and implement a OnPaint handler, that reports a validated rect.

各自安好 2024-12-17 14:49:04

PFD_SUPPORT_GDI 意味着您可以对窗口进行 GDI 绘图。这会强制使用软件 OpenGL 实现,因为您无法将 GDI 绘图(软件)与基于硬件的 OpenGL 绘图一起使用。

因此,不能,同一窗口不能同时拥有硬件 OpenGL(或 D3D)加速和 GDI 支持。如果您对此类窗口的内容发生的情况有疑问,则应该以其他方式解决。也许您可以在视图大小发生更改或其他情况时简单地重新绘制视图。

PFD_SUPPORT_GDI means that you can do GDI drawing to the window. This forces a software OpenGL implementation, because you cannot use GDI drawing (which is software) with hardware-based OpenGL drawing.

So no, you cannot have both hardware OpenGL (or D3D) acceleration and GDI support for the same window. If you're having issues with what happens to the contents of such windows, that is something you should resolve in some other way. Perhaps you could simply redraw the view when its size is changed or something.

为你拒绝所有暧昧 2024-12-17 14:49:04

我认为最好的方法是使用帧缓冲区。处理 OnEraseBackground() 有助于消除闪烁,但 MFC 仍然不想与 OpenGL 很好地配合,所以我不得不使用 GDI 解决方案。

每个视口首先被绘制到它自己的帧缓冲区,然后传输到适当的窗口。

void FrameBuffer::Blit(HDC hDC, int width, int height)
{
    glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, blitBuffer);
    SetDIBitsToDevice(hDC, 0, 0, width, height, 0, 0, 0, height, blitBuffer, &blitInfo, DIB_RGB_COLORS);    
}

该解决方案似乎没有对性能产生任何明显的影响。

I decided the best way to do this was to use a frame buffer. Handling OnEraseBackground() helped with the flicker, but the MFC still just doesn't want to play nice with OpenGL, so I had to go with a GDI solution.

Each viewport first gets drawn to it's own frame buffer, and then blitted to the appropriate window.

void FrameBuffer::Blit(HDC hDC, int width, int height)
{
    glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, blitBuffer);
    SetDIBitsToDevice(hDC, 0, 0, width, height, 0, 0, 0, height, blitBuffer, &blitInfo, DIB_RGB_COLORS);    
}

This solution doesn't seem to be making any visible impact on performance.

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