pyopengl:OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit

File "D:\ProgramData\Anaconda3\envs\pytorch_cpu\lib\site-packages\OpenGL\GLUT\special.py", line 333, in glutInit
    _base_glutInit( ctypes.byref(count), holder )
  File "D:\ProgramData\Anaconda3\envs\pytorch_cpu\lib\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

原因是:pip install pyopengl安装的版本不对
下载whl文件
我的是python3.7+windows+64位: PyOpenGL-3.1.5-cp37-cp37m-win_amd64.whl

测试代码:

#coding:utf-8
import sys
from math import pi as PI
from math import sin, cos
 
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

def drawFunc():
    #清除之前画面
    glClear(GL_COLOR_BUFFER_BIT)
    glRotatef(0.1, 10,5,0)   #(角度,x,y,z)
    glutWireTeapot(0.5)      #画线框茶壶
    #glutSolidTeapot(0.5)      #画实心茶壶
    #刷新显示
    glFlush()
    	    
#使用glut初始化OpenGL
glutInit()
#显示模式:GLUT_SINGLE无缓冲直接显示|GLUT_RGBA采用RGB(A非alpha)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
#窗口位置及大小-生成
glutInitWindowPosition(0,0)
glutInitWindowSize(400,400)
glutCreateWindow(b"first")
 
#调用函数绘制图像
glutDisplayFunc(drawFunc)
glutIdleFunc(drawFunc)      #产生动画函数
#主循环
glutMainLoop()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DYF-AI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值