如何使用PyOpengl或pyglet在桌面上绘图?
我正在编写一个应用程序,希望使用 OpenGL 在 Windows 7 桌面上绘制基本的多边形和椭圆形。根据上一个问题,这可能是通过获取桌面的窗口句柄来实现的,我知道该怎么做。 在没有窗口的 Windows 桌面上绘制 OpenGL
但是,我有两个问题:
你实际上在哪里告诉 OpenGL 要绘制到哪个窗口?我一直在查看 nehe 示例 1,但我根本无法弄清楚它到底在哪里传递 openGL hwnd。我应该给 openGL 一个窗口句柄还是一个设备上下文?
是否可以使用 PyOpenGL 或 Pyglet 来做到这一点?或者我必须用 C 语言编写它,然后将代码包装在 ctypes 中?
I'm writing an application that is looking to draw basic polygons and ellipses on the Windows 7 desktop using OpenGL. According to this previous question, this is possibly by getting the window handle to the desktop, which I know how to do.
Draw OpenGL on the windows desktop without a window
However, I've got two questions:
Where do you actually tell OpenGL what window to draw to? I've been looking through nehe example 1, and I simply can't figure out where exactly it's passing openGL the hwnd. Do I give openGL a window handle or a device context?
Is it possible to do this using PyOpenGL or Pyglet? Or would I have to write it in C, then wrap the code in ctypes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在另一个进程的窗口上执行 OpenGL 是一个非常非常糟糕的主意!为了让 OpenGL 工作,它需要设置窗口的像素格式。然而,窗口的像素格式只能设置一次,因此在外部窗口上执行此操作将导致灾难。
执行此操作的正确方法是使用 PBuffer,它有自己的离屏 HDC,渲染到此 PBuffer 并从 PBuffer 到目标窗口的 BitBlt,但它速度慢。不过我自己从来没有实现过这个,所以我无法直接告诉你它的效果如何。但这听起来是一件值得尝试的有趣的事情,所以也许下次我在我的计算机上启动 Windows 时就会这样做。
Trying to do OpenGL on another process' window is a really, really bad idea! For OpenGL to work it needs to set the window's pixel format. However the pixel format of a window can be set only once, so doing this on a foreign window is a recipe for disaster.
The proper way to do this, but it's slow like nothing else is to use a PBuffer, which has it's own off screen HDC, render to this PBuffer and BitBlt from the PBuffer to the target window. I've never implemented this myself though, so I can't tell you how well this works first hand. But it sounds like an interesting thing to try, so maybe I'm doing that next time I boot Windows on my machine.