glGenVertexArrays function doesn't work in every Python script


I want to create a pyOpenGL program to display quads. When creating a VAO an exception is being thrown.

The glGenVertexArrays function throws this excpetion in my script:

OpenGL.error.NullFunctionError: Attempt to call an undefined function glGenVertexArrays

I guess it has something to do with initialization. (the create_vao function is relevant)

from raw_model import RawModel
from OpenGL.GL import *
from OpenGL.GLUT import *

class Loader:

    __vaos = []
    __vbos = []

    def load_to_vao(self, positions: list):
        vao_id = self.create_vao()
        self.store_data_in_attribute_list(0, positions)
        return RawModel(vao_id, len(positions)//3)

    def clean_up(cls):
        for vao in cls.__vaos:
        for vbo in cls.__vbos:

    def create_vao(cls):
        vao_id = glGenVertexArrays(1)
        return vao_id

    def store_data_in_attribute_list(cls, attribute_number: int, data: list):
        vbo_id = glGenBuffers()
        glBindBuffer(GL_ARRAY_BUFFER, vbo_id)
        glBufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW)
        glVertexAttribPointer(attribute_number, 3, GL_FLOAT, False, 0, 0)
        glBindBuffer(GL_ARRAY_BUFFER, 0)

    def unbind_vao():
        glBindVertexArray(0) (the create_display function is relevant):

from OpenGL.GL import *
from OpenGL.GLUT import *

class DisplayManager:

    def __init__(self, x: int = 1920, y: int = 1080):
        if x is not None: self.__width = x
        if y is not None: self.__height = y

    def create_display(self, window_name):
        glutInitDisplayMode(GLUT_RGBA)                           # initialize colors
        glutInitWindowSize(self.get_width(), self.get_height())  # set windows size
        glutInitWindowPosition(0, 0)                             # set window position
        glutCreateWindow(f"{window_name}")                       # create window (with a name) and set window attribute
        input("This ran")
        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS)  # prevent program from stopping

    def update_display():
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  # Remove everything from screen (i.e. displays all white)
        glLoadIdentity()                                    # Reset all graphic/shape's position
        glutSwapBuffers()                                   # Important for double buffering

    def get_width(self):
        return self.__width

    def get_height(self):
        return self.__height

    def set_window(cls, window):
        cls.__WIND = window

I already tried to include the glutInit function into the script, with no success. I also tried to figure out in which scripts the glGenVertexArrays function works, with no real clue.

Asked By: Andreas Sabelfeld



In my function I called the create_vao method before I even created the window. Swapping the order did the trick.

Answered By: Andreas Sabelfeld
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.