开发者

A problem with using pyglet and pyopengl together

开发者 https://www.devze.com 2023-03-17 16:53 出处:网络
I have the following code: import pyglet from OpenGL.GL import * from OpenGL.GLU import * class Window(pyglet.window.Window):

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开发者_StackOverflow_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.


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.


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!


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.

pip install hg+https://pyglet.googlecode.com/hg/

You will need mercurial installed. If you're using a virtualenv you can simply use:

pip install mercurial
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号