0

I am newbie to python Open GL coding, I installed it from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl i was trying to basic but after while i got the error

Attempt to call an undefined function glCreateProgram, check for bool(glCreateProgram) before calling

Here is the code

from OpenGL.GL import *
from OpenGL.GLUT import*
from OpenGL.GLE import*
import sys
import numpy as np



vertix = np.array([-0.5, -0.5, 0.0,
                   0.5, -0.5, 0.0,
                   0.0, 0.5, 0.0,])

def fig():
    pgm = glCreateProgram()
    #1st shader obj
    
    shader_obj = glCreateShader(GL_VERTEX_SHADER)
    shader_frag_obj = glCreateShader(GL_FRAGMENT_SHADER)
    glShaderSource(shader_frag_obj,VERTEX_SHADER_SOURCE)
    glShaderSource(shader_obj,VERTEX_SHADER_SOURCE)
    glCompileShader(shader_obj)
    glCompileShader(shader_frag_obj)
    
    glAttachShader(pgm,shader_obj)
    glAttachShader(pgm,shader_frag_obj)
    glLinkProgram(pgm)
    

    #2nd buffer obj
    buf_obj = glGenBuffer(1)
    glBindBuffer(GL_ARRAY_BUFFER, buf_obj)
    glBufferData(GL_ARRAY_BUFFER,vertix.size,vertix,GL_DRAW_STATIC)
    
    
    #3rd vertex obj
    
    vertex_array_obj = glGenVertexArrays(1)
    glBindVertexArray(vertex_array_obj)
    glEnableVertexAttribArray(0)
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3, c_void_p(0))

    
fig()


def render():
    glClear(GL_COLOR_BUFFER_BIT)
    glUseProgram(pgm)
   
    glDrawArrays(GL_TRIANGLE, 0, 3)
        

glutInit(sys.argv)
glutInitWindowSize(800,600)
glutCreateWindow("Hyper Modern")
glutDisplayFunc(render)
glutMainLoop()

I tried looking on internet about error but cant find many stuff about this particular solution to it so it will be grateful if anyone can suggest anything

Ayushkr3
  • 1
  • 2
  • You call `fig()` before you call `glutCreateWindow´. OpenGL calls are only valid after the OpenGL context has been created. – BDL Sep 27 '22 at 13:59
  • @BDL so its all syntax error not any installation problem right ? – Ayushkr3 Sep 27 '22 at 14:03
  • It's not a syntax error. Syntax errors are when your code isn't valid python syntax. But you have a correct syntax, just wrong logic. – BDL Sep 27 '22 at 14:05

0 Answers0