标签:nbsp end argv demo dem sys.argv python 使用 pre
pyOpenGL Installation
Package Version
------------------- -------
numpy 1.14.2
PyOpenGL 3.1.0
PyOpenGL-accelerate 3.1.0
demo1
1 # -*- coding: utf-8 -*- 2 from OpenGL.GL import * 3 from OpenGL.GLU import * 4 from OpenGL.GLUT import * 5 6 7 def init(): 8 glClearColor(1, 1, 1, 1) 9 gluOrtho2D(-1, 1, -1, 1) 10 11 12 def triangle(): 13 glClear(GL_COLOR_BUFFER_BIT) 14 glColor3f(1, 0, 0) 15 glBegin(GL_TRIANGLES) 16 17 glColor3f(1, 0, 0) 18 glVertex2f(-1, -1) 19 20 glColor3f(0, 1, 0) 21 glVertex2f(1, -1) 22 23 glColor3f(0, 0, 1) 24 glVertex2f(0, 1) 25 26 glEnd() 27 glFlush() 28 29 30 def main(): 31 glutInit(sys.argv) 32 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) 33 glutInitWindowSize(800, 600) 34 glutInitWindowPosition(50, 50) 35 glutCreateWindow("Triangle") 36 glutDisplayFunc(triangle) 37 init() 38 glutMainLoop() 39 40 41 if __name__ == ‘__main__‘: 42 main()
demo2
# -*- coding: utf-8 -*- from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * def drawFunc(): # 清楚之前画面 glClear(GL_COLOR_BUFFER_BIT) glRotatef(0.01, 3, 2, 1) # (角度,x,y,z) glutWireTeapot(0.5) glutWireCube(0.5) # 刷新显示 glFlush() # 使用glut初始化OpenGL glutInit() # 显示模式:GLUT_SINGLE无缓冲直接显示|GLUT_RGBA采用RGB(A非alpha) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA) # 窗口位置及大小-生成 glutInitWindowPosition(0, 0) glutInitWindowSize(400, 400) wnd = glutCreateWindow(b"first") # 调用函数绘制图像 glutDisplayFunc(drawFunc) glutIdleFunc(drawFunc) # 主循环 glutMainLoop()
标签:nbsp end argv demo dem sys.argv python 使用 pre
原文地址:https://www.cnblogs.com/coder211/p/9056030.html