I am experimenting with OpenGL(PyOpenGL) 3.3 and in Python 3.9:
vertexShader = glCreateShader(GL_VERTEX_SHADER)
glShaderSource(vertexShader, 1, open("assets\\vertexSrc.glsl", "r").read(), None) << ERROR HERE
glCompileShader(vertexShader)
Got this error:
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
I was trying to define the shader source, but then got that error.
open("assets\\vertexSrc.glsl", "r").read()
returns a python string. To create the shader from a python string you have to use overload for the python objects. See the PyOpenGL signatures of glShaderSource
:
glShaderSource( GLuint ( shader ) , GLsizei ( count ) , const GLchar **( string ) , const GLint *( length ) )-> void glShaderSource( shaderObj , string )
Change:
glShaderSource(vertexShader, 1, open("assets\\vertexSrc.glsl", "r").read(), None)
glShaderSource(vertexShader, open("assets\\vertexSrc.glsl", "r").read())