我开始学习OpenGL,并尝试在此tutorial中运行该程序。这是我从该页面得到的代码。我不得不降低着色器中的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)
答案 0 :(得分:2)
错误是其中一个库中的错误,而不是代码中的错误。基本上Python告诉你,调用perspectiveMatrix
的方式与函数的实际签名不匹配。
您需要向您使用的库的创建者提交错误报告。