I've been told to switch legacy profile to core profile from other stackoverflow posts but I can't seem to find a way to do that. So I'm positing a more updated error post to help me figure out a way.
CODE:
import glfw, numpy
from OpenGL.GL import *
import OpenGL.GL.shaders
def main():
if not glfw.init():
return
window = glfw.create_window(800,600,"My OpenGL Window", None, None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
triangle = [-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0]
triangle = numpy.array(triangle, dtype = numpy.float32)
vertex_shader = """
#version 460
in vec3 position;
void main()
{
gl_Position = position;
}
"""
fragment_shader = """
#version 460
void main()
{
gl_FragColor = vec4(1.0f,0.0f,0.0f,1.0f);
}
"""
shader = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(vertex_shader, GL_VERTEX_SHADER),
OpenGL.GL.shaders.compileShader(fragment_shader,GL_FRAGMENT_SHADER))
VBO = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, VBO)
glBufferData(GL_ARRAY_BUFFER, 36, triangle, GL_STATIC_DRAW)
position = glGetAttribLocation(shader, "position")
glVertexAttribPoint(position, 3, GL_FLOAT, GL_FALSE, 0, None)
glEnableVertexAttribArray(position)
glUseProgram(shader)
glClearColor(0.2, 0.3, 0.2, 1.0)
while not glfw.window_should_close(window):
glfw.poll_events()
glClear(GL_COLOR_BUFFER_BIT)
glDrawArrays(GL_TRIANGLES, 0, 3)
glfw.swap_buffers(window)
glfw.terminate()
if __name__ == "__main__":
main()
I keep getting this error
Traceback (most recent call last):
File "/Users/Datboi/Desktop/Python/Opengl/main.py", line 71, in <module> main() File "/Users/Datboi/Desktop/Python/Opengl/main.py", line 43, in main shader = OpenGL.GL.shaders.compileProgram(OpenGL.GL.shaders.compileShader(vertex_shader, GL_VERTEX_SHADER), File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/OpenGL/GL/shaders.py", line 226, in compileShader shaderType, RuntimeError: ('Shader compile failure (0): b"ERROR: 0:2: \'\' : version \'460\' is not supported\\n"', [b'\n #version 460\n in vec3 position;\n \n void main()\n {\n gl_Position = position;\n }\n\n '], GL_VERTEX_SHADER)
I can't seem to find anything to fix this issue. I'm new to OpenGL/PyOpenGL and couldn't find any posts that have asked roughly the same question