opengl 错误,空函数错误:尝试调用未定义的函数glutInit,在调用之前检查bool(glutInit)

luaexgnf  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(230)

我正在遵循这个easy guide,以便迈出我进入PyOpenGL的第一步。
1.我安装了pip install PyOpenGL PyOpenGL_accelerate,一切正常。
1.我通过测试代码测试了安装:
import OpenGL.GL import OpenGL.GLUT import OpenGL.GLU print(“Imports successful!”)#如果您在控制台上看到此消息,则说明安装成功
都好
我现在运行此脚本:

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()

我收到的错误是OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling
所以我在网上看了一些指南,他们指出要从这里下载wheel。所以我继续下载PyOpenGL_accelerate‑3.1.5‑cp38‑cp38‑win_amd64.whlPyOpenGL‑3.1.5‑cp38‑cp38‑win_amd64.whl,因为我运行的是Python 3.8

  1. pip install .\PyOpenGL_accelerate-3.1.5-cp39-cp39-win_amd64.whl返回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返回PyOpenGL-accelerate is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
    一个如此简单的指引怎么会让我走到如此痛苦的结果?
    如何检查Visual C++ 14.0 build tools是否已安装?也许这是我唯一遗漏的步骤?
au9on6nz

au9on6nz1#

软件包中缺少 freeglut DLL。
卸载“PyOpenGL”:

pip uninstall pyopengl

下载软件包轮(例如:“PyOpenGL‑3.1.6‑cp311‑cp311‑win_amd64.whl”),Python扩展包的非官方Windows二进制文件,并安装它:

pip install PyOpenGL‑3.1.6‑cp311‑cp311‑win_amd64.whl

相关问题