0

我开始学习 OpenGL,并尝试运行本教程中的程序。这是我从该页面收集的代码。我不得不降低着色器中的 GLSL 版本才能让它在我的笔记本电脑上运行(它们是 330)。

from OpenGLContext import testingcontext
BaseContext = testingcontext.getInteractive()

from OpenGL.GL import *
from OpenGL.arrays import vbo
from OpenGLContext.arrays import *
from OpenGL.GL import shaders

class TestContext( BaseContext ):
    """Creates a simple vertex shader..."""

    def OnInit(self):

        VERTEX_SHADER = shaders.compileShader("""
            #version 130
            void main() {
                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
            }
            """, GL_VERTEX_SHADER)

        FRAGMENT_SHADER = shaders.compileShader("""
            #version 130
            void main() {
                 gl_FragColor = vec4(0, 1, 0, 1);
            }""", GL_FRAGMENT_SHADER)

        self.shader = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)

        self.vbo = vbo.VBO(
            array( [
                [  0, 1, 0 ],
                [ -1,-1, 0 ],
                [  1,-1, 0 ],
                [  2,-1, 0 ],
                [  4,-1, 0 ],
                [  4, 1, 0 ],
                [  2,-1, 0 ],
                [  4, 1, 0 ],
                [  2, 1, 0 ],
            ],'f')
        )

    def render(self, mode):
        shaders.glUseProgram(self.shader)

        try:
            self.vbo.bind()
            try:
                glEnableClientState(GL_VERTEX_ARRAY)
                glVertexPointerf(self.vbo)

                glDrawArrays(GL_TRIANGLES, 0, 9)
            finally:
                self.vbo.unbind()
                glDisableClientState(GL_VERTERX_ARRAY)
        finally:
            shaders.glUseProgram(0)

if __name__ == "__main__":
    TestContext.ContextMainLoop()

这是我运行程序时遇到的错误。如果我将鼠标移动到出现的小窗口顶部,则会重复该错误,因此该应用程序仍然存在,但没有真正发挥作用。该窗口显示应用程序启动时其背后的内容,因此没有真实图片。

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 314, in 'calling callback function'
  File "/usr/lib/python2.7/site-packages/OpenGLContext/events/glutevents.py", line 33, in glutOnMouseMove
    self.triggerPick()
  File "/usr/lib/python2.7/site-packages/OpenGLContext/context.py", line 590, in triggerPick
    self.OnDraw()
  File "/usr/lib/python2.7/site-packages/OpenGLContext/context.py", line 515, in OnDraw
    visibleChange = self.renderPasses( self )
  File "/usr/lib/python2.7/site-packages/OpenGLContext/passes/renderpass.py", line 866, in __call__
    return FLAT( context )
  File "/usr/lib/python2.7/site-packages/OpenGLContext/passes/flatcompat.py", line 298, in __call__
    self.setViewPlatform( vp )
  File "/usr/lib/python2.7/site-packages/OpenGLContext/passes/flatcompat.py", line 334, in setViewPlatform
    self.projection = vp.viewMatrix().astype('f')
  File "/usr/lib/python2.7/site-packages/OpenGLContext/move/viewplatform.py", line 158, in viewMatrix
    inverse=inverse,
  File "tmatrixaccel.pyx", line 55, in vrml_accelerate.tmatrixaccel.perspectiveMatrix (src/tmatrixaccel.c:1990)
TypeError: perspectiveMatrix() got an unexpected keyword argument 'inverse'

谈到 OpenGL,我完全是个菜鸟,所以我真的不知道从哪里开始寻找问题,因为它甚至不是直接来自我的代码,而是通过一些回调。我是否有某种不兼容的软件包?

我的版本:

Python 2.7.5 (default, Oct  8 2013, 12:19:40) 
[GCC 4.8.1 20130603 (Red Hat 4.8.1-1)] on linux2

PyOpenGL                  - Standard OpenGL bindings for Python
  INSTALLED: 3.1.0a3 (latest)

OpenGLContext             - Demonstration and testing contexts for PyOpenGL/OpenGL-ctypes
  INSTALLED: 2.2.0a3 (latest)

PyOpenGL-accelerate       - Acceleration code for PyOpenGL
  INSTALLED: 3.1.0a3 (latest)

OpenGLContext-full        - Installs all of OpenGLContext with optional dependencies
  INSTALLED: 2.1.0a9 (latest)
4

1 回答 1

2

该错误是使用的库之一中的错误,而不是您的代码中的错误。从本质上讲,Python 告诉您,perspectiveMatrix调用方式喜欢,与函数的实际签名不匹配。

您需要向您使用的库的创建者提交错误报告。

于 2013-11-08T16:11:41.967 回答