python+opengl显示三维模型小程序

在win7+python3.5环境下配置opengl,并显示三维模型

首先安装opengl:

已经安装python的系统会自动安装pip,所以只需要一句pip命令就可以安装opengl了,命令如下:

pip install PyOpenGL PyOpenGL_accelerate	

然后在python 中import相关功能,运行后会出现错误

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

或者:

SyntaxError: multiple statements found while compiling a single statement

可能是缺少相关dll文件,可以在这里下载到     http://pan.baidu.com/s/1dFhC8G5

拷到你建立的工程目录下,就是你写的程序的目录下就可以了。

然后运行下面的程序,就应该能够显示茶壶模型了。

from OpenGL.GL import *

from OpenGL.GLU import *

from OpenGL.GLUT import *

def drawFunc():

    #清楚之前画面

    glClear(GL_COLOR_BUFFER_BIT)

    glRotatef(0.1, 0,5,0)   #(角度,x,y,z)

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

《python+opengl显示三维模型小程序》

    原文作者:renjiangui
    原文地址: https://blog.csdn.net/renjiangui/article/details/76146160
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞