我正在尝试OpenGL(PyOpenGL)3.3和Python 3.9:
vertexShader = glCreateShader(GL_VERTEX_SHADER)
glShaderSource(vertexShader, 1, open("assets\\vertexSrc.glsl", "r").read(), None) << ERROR HERE
glCompileShader(vertexShader)
得到此错误:
Traceback (most recent call last):
File "C:\Users\admin\Desktop\OpenGL\Python\Exploring\main.py", line 44, in <module>
glShaderSource(vertexShader, 1, vertex_src, None) # Defining the vertex shader source
File "src/latebind.pyx", line 39, in OpenGL_accelerate.latebind.LateBind.__call__
File "src/wrapper.pyx", line 299, in OpenGL_accelerate.wrapper.Wrapper.__call__
File "src/wrapper.pyx", line 161, in OpenGL_accelerate.wrapper.PyArgCalculator.c_call
File "src/wrapper.pyx", line 128, in OpenGL_accelerate.wrapper.PyArgCalculatorElement.c_call
File "src/wrapper.pyx", line 122, in OpenGL_accelerate.wrapper.PyArgCalculatorElement.c_call
File "C:\Users\admin\AppData\Local\Programs\Python\Python39\lib\site-packages\OpenGL\converters.py", line 305, in stringArray
value = [as_8_bit(x) for x in arg]
TypeError: ("'int' object is not iterable", <bound method StringLengths.stringArray of <OpenGL.converters.StringLengths object at 0x0000015525B19430>>)
Process finished with exit code 1
我试图定义着色器源,但后来得到了这个错误。
2条答案
按热度按时间7rtdyuoh1#
open("assets\\vertexSrc.glsl", "r").read()
返回python字符串。要从python字符串创建着色器,必须为python对象使用重载。查看glShaderSource
的PyOpenGL签名:变更:
glShaderSource(vertexShader, 1, open("assets\\vertexSrc.glsl", "r").read(), None)
clj7thdc2#
您需要将着色器源代码作为字符串列表传递。