pyglet和pyopengl一起使用的问题
我有以下代码:
import pyglet
from OpenGL.GL import *
from OpenGL.GLU import *
class Window(pyglet.window.Window):
def __init__(self,width,height):
super(Window,self).__init__(width,height)
glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
def on_draw(self):
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
#I know this is deprecated
glTranslatef(0.0,0.0,-5.0)
glColor3f(1.0,1.0,1.0)
glBegin(GL_TRIANGLES)
glVertex3f(0.0,0.0,0.0)
glVertex3f(0.0,1.0,0.0)
glVertex3f(1.0,0.0,0.0)
glEnd()
def on_resize(self,width,height):
glViewport(0,0,width,height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0,float(width)/float(height),0.1,100.0)
glMatrixMode(GL_MODELVIEW)
当我使用 pyglet 的 opengl 绑定时,它按预期工作。然而,当我使用 pyopengl 时,我只看到一团乱麻。
I have the following code:
import pyglet
from OpenGL.GL import *
from OpenGL.GLU import *
class Window(pyglet.window.Window):
def __init__(self,width,height):
super(Window,self).__init__(width,height)
glClearDepth(1.0)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_SMOOTH)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
def on_draw(self):
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
#I know this is deprecated
glTranslatef(0.0,0.0,-5.0)
glColor3f(1.0,1.0,1.0)
glBegin(GL_TRIANGLES)
glVertex3f(0.0,0.0,0.0)
glVertex3f(0.0,1.0,0.0)
glVertex3f(1.0,0.0,0.0)
glEnd()
def on_resize(self,width,height):
glViewport(0,0,width,height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0,float(width)/float(height),0.1,100.0)
glMatrixMode(GL_MODELVIEW)
When I use pyglet's opengl bindings it works as expected. However, when I use pyopengl, I only see a jumbled mess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
每个工具包都认为OpenGL窗口属于自己。其中只有一个是正确的,因此只有其中之一能够正确渲染。
由于它们都公开 OpenGL,因此没有理由尝试在同一程序中使用两者。
Each toolkit believes that the OpenGL window belongs to themselves. Only one of them is right, and therefore only one of them will be able to render correctly.
Since they both expose OpenGL, there's no reason to try to use both in the same program.
我必须同意尼科尔的观点。
每个人都认为该窗口属于自己,因此只有一个能够正确渲染,为什么不尝试使用 PyOpenGL 创建窗口,哦,并获取 Escape 的关键代码:
转义 = chr(27)
祝你好运!
I have to agree with Nicol.
Each thinks that the window belongs to it, so only one will be able to render correctly, why don't you try creating the window with PyOpenGL, oh and to get the key code for Escape:
escape = chr(27)
Good luck!
我可以确认 PyOpenGL 和 Pyglet 确实可以一起工作。
由于 python opengl 调用只是地址空间中相同 GL 标头/dll 的包装器,因此它们都重定向到相同的函数。
我还可以确认您的代码可以呈现。
我从源代码使用 Pyglet,尝试以下操作直接从存储库 HEAD 安装。
您需要安装 Mercurial。如果您使用的是 virtualenv,您可以简单地使用:
I can confirm that PyOpenGL and Pyglet do work together.
As the python opengl calls are just wrappers to the same GL header / dll in the address space, they're all redirecting to the same functions.
I can also confirm that your code renders.
I'm using Pyglet from source, try the following to install directly from the repository HEAD.
You will need mercurial installed. If you're using a virtualenv you can simply use: