pyopengl
pyopengl copied to clipboard
Attempt to call an undefined function glutInitDisplayMode, check for bool(glutInitDisplayMode) before calling
Hi, thank you for your repo!
I am currently trying to learn how to use PyOpenGL, and my code is as follows:
import numpy as np
import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
class Demo(object):
def __init__(self):
# self.geometry = geometry
glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowSize(400, 400)
glutCreateWindow(b"Hello OpenGL")
glutDisplayFunc(self.draw_geometry)
self.init_condition()
glutMainLoop()
def init_condition(self):
glClearColor(1.0, 1.0, 1.0, 1.0)
gluOrtho2D(-8.0, 8.0, -8.0, 8.0)
def render(self):
pass
def draw_geometry(self):
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 0.0, 0.0) B
glBegin(GL_QUADS)
glVertex2f(-2, 2)
glVertex2f(-2, 5)
glVertex2f(-5, 5)
glVertex2f(-5, 2)
glEnd()
glFlush()
if __name__ == "__main__":
Demo()
The error message is as follows:
NullFunctionError Traceback (most recent call last)
Cell In[14], line 33
31 glFlush()
32 if __name__ == "__main__":
---> 33 Demo()
Cell In[14], line 10, in Demo.__init__(self)
7 def __init__(self):
8 # self.geometry = geometry
9 glutInit()
---> 10 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
11 glutInitWindowSize(400, 400)
12 glutCreateWindow(b"Hello OpenGL")
File E:\anaconda\envs\opengl\lib\site-packages\OpenGL\platform\baseplatform.py:423, in _NullFunctionPointer.__call__(self, *args, **named)
421 pass
422 else:
--> 423 raise error.NullFunctionError(
424 """Attempt to call an undefined function %s, check for bool(%s) before calling"""%(
425 self.__name__, self.__name__,
426 )
427 )
NullFunctionError: Attempt to call an undefined function glutInitDisplayMode, check for bool(glutInitDisplayMode) before calling
I followed some tutorials online and downloaded the related complete packages from the website : https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl. Unfortunately, this website is now closed.
Currently, the tutorials I’ve found are focused on the function glutInit, but I don’t understand how it differs from the function glutInitDisplayMode.I tried downloading glut and freeglut and placed the corresponding files in the site-packages folder, as shown in the picture:
However, this still did not solve the problem.
I am using:
Python 3.8 PyOpenGL-3.1.6 Windows 11
Could you please help me with this? Thanks!
This might help: Christoph Gohlke recently created new Windows wheels here: https://github.com/cgohlke/pyopengl-build https://github.com/cgohlke/pyopengl-build/releases