Python OpenGL基本配置

2020-01-07 21:20:41 浏览数 (1)

参考:http://pyopengl.sourceforge.net

一、pip 安装 PyOpenGL

pip install PyOpenGL PyOpenGL_accelerate

二、测试代码

代码语言:javascript复制
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

def init():
    glClearColor(1,1,1,1)
    gluOrtho2D(-1,1,-1,1)

def triangle():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1,0,0)
    glBegin(GL_TRIANGLES)

    glColor3f(1,0,0)
    glVertex2f(-1, -1)
    
    glColor3f(0,1,0)
    glVertex2f(1, -1)
    
    glColor3f(0,0,1)
    glVertex2f(0, 1)
    
    glEnd()
    glFlush()

def main():
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
    glutInitWindowSize(800,600)
    glutInitWindowPosition(50,50)
    glutCreateWindow("Triangle")
    glutDisplayFunc(triangle)
    init()
    glutMainLoop()

if __name__ == '__main__':
    main()

运行结果,绘制出一个彩色三角形:

0 人点赞