PyOpenGL 过剩 Window
PyOpenGL Glut Window
所以我最近开始使用 PyOpenGL 的 GLUT 模块,但找不到任何关于它的简单教程(任何链接都将不胜感激),我只想使用 glutCreateWindow('window')
创建一个过剩 window,但是一旦 window 弹出它就消失了。我尝试在我的主要功能中使用 glutMainLoop()
,但它只是给出了一个错误。
from OpenGL.GLU import *
from OpenGL.GL import *
glutInit()
def main():
glutCreateWindow('window')
glutMainLoop()
if __name__=='__main__':main()
您必须设置 glutDisplayFunc
回调。过剩主循环调用显示回调。
最小示例:
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
glutInit()
def display():
glClearColor(1, 0, 0, 0) # red
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
# your rendering goes here
# [...]
glutSwapBuffers()
glutPostRedisplay()
def main():
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
glutCreateWindow('window')
glutDisplayFunc(display)
glutMainLoop()
if __name__=='__main__':
main()
glutInitDisplayMode
sets the initial display mode. glutSwapBuffers
swaps the buffers of the current window ant and thus updates the display. glutPostRedisplay
将当前 window 标记为重新显示,因此导致显示不断重绘,这是动画所必需的。
所以我最近开始使用 PyOpenGL 的 GLUT 模块,但找不到任何关于它的简单教程(任何链接都将不胜感激),我只想使用 glutCreateWindow('window')
创建一个过剩 window,但是一旦 window 弹出它就消失了。我尝试在我的主要功能中使用 glutMainLoop()
,但它只是给出了一个错误。
from OpenGL.GLU import *
from OpenGL.GL import *
glutInit()
def main():
glutCreateWindow('window')
glutMainLoop()
if __name__=='__main__':main()
您必须设置 glutDisplayFunc
回调。过剩主循环调用显示回调。
最小示例:
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
glutInit()
def display():
glClearColor(1, 0, 0, 0) # red
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
# your rendering goes here
# [...]
glutSwapBuffers()
glutPostRedisplay()
def main():
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA)
glutCreateWindow('window')
glutDisplayFunc(display)
glutMainLoop()
if __name__=='__main__':
main()
glutInitDisplayMode
sets the initial display mode. glutSwapBuffers
swaps the buffers of the current window ant and thus updates the display. glutPostRedisplay
将当前 window 标记为重新显示,因此导致显示不断重绘,这是动画所必需的。