首页 > 解决方案 > How do I render a win32 window to an opengl texture?

问题描述

I want to be able to render a win32 control inside an OpenGL texture. In order to be able to 3d transform it. Specifically I want to embed Internet explorer to show webpages and video inside a 3D transformed window.

How do I render a win32 window to a texture in a fast enough way (I need to keep 60 fps)?

标签: c++winapiopengl

解决方案


有几种方法可以解决。在所有情况下,您都需要从目标窗口 ( GetDC, ) 获取设备上下文 (DC GetDCEx)。

然后,您可以直接读取像素(GetPixel);或将内容 blit 到您自己的 DC ( BitBlt) 中,然后访问该内容 (例如GetDIBits)。

既然你想“嵌入”Internet Explorer,那么你可能意味着隐藏它的窗口;您将需要考虑如何在不可见、部分可见等的窗口上进行上述工作。还要考虑您的 Windows 版本和/或 DWM 是否可能被禁用(因此窗口的内容可能不可用)。看看PrintWindow强制WM_PAINT/ WM_PRINT

一个可以向您介绍所有这些并具有完整示例的小型 MSDN 指南是:捕获图像

在任何情况下,您都可以通过将其他浏览器/引擎嵌入为库(例如Chromium Embedded Framework (CEF)Qt 的 WebEngineElectron ...)来寻求替代解决方案。


推荐阅读