Python Forum

Full Version: NullFunctionError opengl glutInit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

window = 0                                             # glut window number
width, height = 500, 400                               # window size

def draw():                                            # ondraw is called all the time
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen
    glLoadIdentity()                                   # reset position
    
    # ToDo draw rectangle
    
    glutSwapBuffers()                                  # important for double buffering
    

# initialization
glutInit()                                             # initialize glut
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
glutInitWindowSize(width, height)                      # set window size
glutInitWindowPosition(0, 0)                           # set window position
window = glutCreateWindow("noobtuts.com")              # create window with title
glutDisplayFunc(draw)                                  # set draw function callback
glutIdleFunc(draw)                                     # draw all the time
glutMainLoop()                                         # start everything
Error:
Traceback (most recent call last):   File "graphic.py", line 47, in <module>     if __name__ == '__main__': main()   File "graphic.py", line 9, in main     glutInit(sys.argv)   File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-package s\pyopengl-3.1.1a1-py3.5.egg\OpenGL\GLUT\special.py", line 333, in glutInit     _base_glutInit( ctypes.byref(count), holder )   File "C:\Users\User\AppData\Local\Programs\Python\Python35-32\lib\site-package s\pyopengl-3.1.1a1-py3.5.egg\OpenGL\platform\baseplatform.py", line 407, in __ca ll__     self.__name__, self.__name__, OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
i copied and paste this from the internet to my project,so there should not be any error.
I am only 15 years old,so please dont use too much hard to understand or mathematical term in the answer.

Why is no one answering me?
Apparently, there is no glutInit in the namespace. There is a hint in the error message to check for glutInit() before calling it.
The bottom line.

"check for bool(glutInit) before calling"

You can do the same calling dir():
if 'glutInit' in dir():
Thanks,let me try it first.
I will come back if there is still error.
I also heard from another website that glut needs to be downloaded seperately because it does not come with pypl PyOpenGL download.
It's quite possible. This module is big  Smile