Python 一个pygame窗口中的两个OpenGL屏幕

Python 一个pygame窗口中的两个OpenGL屏幕,python,opengl,pygame,opengl-3,Python,Opengl,Pygame,Opengl 3,我将pygame与opengl一起使用,但在同一pygame窗口中设置许多opengl屏幕(或“摄像头”)时遇到问题。我的代码类似于 {initialize the screen using pygame.display.set_mode, glViewport, gluPersepctive etc} while 1: {obtain pressed keys from the keyboard and do stuff} {draw opengl objects}

我将pygame与opengl一起使用,但在同一pygame窗口中设置许多opengl屏幕(或“摄像头”)时遇到问题。我的代码类似于

{initialize the screen using pygame.display.set_mode, glViewport, gluPersepctive etc}

while 1:
    {obtain pressed keys from the keyboard and do stuff}

    {draw opengl objects}

    pygame.display.flip()

现在,我要做的是把所有这些都做四次,然后在同一个pygame窗口中的四个不同位置绘制屏幕。我试图将opengl图形放入for循环,并在其中更改glViewport,但没有取得任何进展。那么我应该运行四次哪些命令来绘制四个不同的opengl屏幕呢

实际上,我发现了代码的问题。下面是更正的(伪)代码

{initialize the screen using pygame.display.set_mode, glViewport, gluPersepctive etc}
screen_params=[(0.,0.,0.5,0.5),(0.5,0.5,0.5,0.5),(0.,0.5,0.5,0.5),(0.5,0.,0.5,0.5)]
while 1:
    {obtain pressed keys from the keyboard and do stuff}
    glClearColor(1.0, 1.0, 1.0, 0.0)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    for s in screen_params:
        glViewport(int(WIDTH*S[0]), int(HEIGHT*S[1]), int(WIDTH*S[2]), int(HEIGHT*S[3]))
        {draw opengl objects}
pygame.display.flip()
关键是不要像我以前做的那样在每个循环中运行Clear命令(duh),但是如果屏幕的宽度和高度是您的屏幕大小,上面的代码将把您以前画的任何东西复制到四个较小的屏幕上。

“但没有取得任何进展”不是一个有用的问题陈述。你应该展示你已经拥有的,并解释到底是什么问题。从概念上讲,每次使用不同的视口绘制多次都是任务的可行解决方案,但不清楚您到底做错了什么。