This error occured when I try to use pyopengl in Mac. I found the solution with windows. But I don't know how to fix it in Mac.
This is my code:
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import os
def initFunc():
glDisable(GL_DEPTH_TEST)
glClearColor(0.0, 0.0, 0.0, 0.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0, 400.0, 0.0, 400.0)
def displayFunc():
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 1.0, 1.0)
glBegin(GL_TRIANGLES)
glVertex2f(10.0, 10.0)
glVertex2f(10.0, 100.0)
glVertex2f(100.0, 100.0)
glEnd()
glFlush()
if __name__ == '__main__':
glutInit()
glutInitWindowSize(400,400)
glutCreateWindow("GL test")
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
glutDisplayFunc(displayFunc)
initFunc()
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process
"Python" to true' ''')
# prevent GL window from appearing behind other applications
glutMainLoop()
This is the error
Traceback (most recent call last):
File "/Users/wupeihan/Project/learning/python/opengl/traingle.py", line 25, in <module>
glutInit()
File "/Users/wupeihan/miniconda3/envs/opengl/lib/python3.7/site-
packages/OpenGL/GLUT/special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )
File "/Users/wupeihan/miniconda3/envs/opengl/lib/python3.7/site-
packages/OpenGL/platform/baseplatform.py", line 425, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for
bool(glutInit) before calling
I want to know how to solve it in Mac.