pyopengl 安装与测试

笔者通过PyCharm安装pyopengl,然后运行测试程序会出现错误 :OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

https://stackoverflow.com/questions/26700719/pyopengl-glutinit-nullfunctionerror

正确的安装方法为下载.whl文件,然后通过pip安装,whl下载网址为:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl

 

请下载跟你python版本一样的whl文件,笔者Python版本为3.5

  • PyOpenGL‑3.1.4‑cp35‑cp35m‑win32.whl
  • PyOpenGL‑3.1.4‑cp35‑cp35m‑win_amd64.whl
  • PyOpenGL_accelerate‑3.1.4‑cp35‑cp35m‑win32.whl
  • PyOpenGL_accelerate‑3.1.4‑cp35‑cp35m‑win_amd64.whl

记得先卸载PyCharm 安装的pyopengl,通过

pip uninstall PyOpenGL

pip uninstall PyOpenGL-accelerate

如果你的电脑是64位,则使用如下命令安装:

pip install PyOpenGL‑3.1.4‑cp35‑cp35m‑win_amd64.whl

pip install PyOpenGL_accelerate‑3.1.4‑cp35‑cp35m‑win_amd64.whl

如果你的电脑是32位,则使用如下命令安装:

pip install PyOpenGL‑3.1.4‑cp35‑cp35m‑win32.whl

pip install PyOpenGL_accelerate‑3.1.4‑cp35‑cp35m‑win32.whl

 

测试代码:

如下是显示茶壶的测试代码:

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

def drawFunc():
    glClear(GL_COLOR_BUFFER_BIT)
    # glRotatef(1, 0, 1, 0)
    glutWireTeapot(0.5)
    glFlush()

glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA)
glutInitWindowSize(400, 400)
glutCreateWindow("First")
glutDisplayFunc(drawFunc)
# glutIdleFunc(drawFunc)
glutMainLoop()

运行结果如下所示:

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值