Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

python - PyOpenGL :: OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

I'm following this very easy guide in order to make my first steps into PyOpenGL.

  1. I installed pip install PyOpenGL PyOpenGL_accelerate , all good.

  2. I tested the installation through the test code:

    import OpenGL.GL import OpenGL.GLUT import OpenGL.GLU print("Imports successful!") # If you see this printed to the console then installation was successful

all good

I now run this script:

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

w,h= 500,500
def square():
    glBegin(GL_QUADS)
    glVertex2f(100, 100)
    glVertex2f(200, 100)
    glVertex2f(200, 200)
    glVertex2f(100, 200)
    glEnd()

def iterate():
    glViewport(0, 0, 500, 500)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0.0, 500, 0.0, 500, 0.0, 1.0)
    glMatrixMode (GL_MODELVIEW)
    glLoadIdentity()

def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    iterate()
    glColor3f(1.0, 0.0, 3.0)
    square()
    glutSwapBuffers()

glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(500, 500)
glutInitWindowPosition(0, 0)
wind = glutCreateWindow("OpenGL Coding Practice")
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen)
glutMainLoop()

And the error I receive is OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

So i read a few guides online and they point to download the wheel from here. So I go ahead and I download PyOpenGL_accelerate?3.1.5?cp38?cp38?win_amd64.whl and PyOpenGL?3.1.5?cp38?cp38?win_amd64.whl because I'm running Python 3.8

  1. pip install .PyOpenGL_accelerate-3.1.5-cp39-cp39-win_amd64.whl returns PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
  2. pip install .PyOpenGL_accelerate-3.1.5-cp38-cp38-win_amd64.whl returns PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.

How can a so simple guide lead me to a so painful result?

How can I check if Visual C++ 14.0 build tools is installed. Maybe that is the only step I'm missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The freeglut DLL is missing from the package.

Unistall "PyOpenGL":

pip uninstall pyopengl

Download the package wheel ("PyOpenGL?3.1.5?cp39?cp39?win_amd64.whl") from, Unofficial Windows Binaries for Python Extension Packages and install it:

pip install PyOpenGL?3.1.5?cp39?cp39?win_amd64.whl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...