两个 OpenGL 屏幕合二为一 pygame window
Two OpenGL screens in one pygame window
我将 pygame 与 opengl 一起使用,但我在同一个 pygame window 中设置多个 opengl 屏幕(或 "cameras")时遇到问题。我的代码类似于
{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 window。我试图将 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()
关键是不要 运行 每个循环中的清除命令 (duh),这是我之前所做的,但是如果 WIDTH 和 HEIGHT 是屏幕尺寸。
我将 pygame 与 opengl 一起使用,但我在同一个 pygame window 中设置多个 opengl 屏幕(或 "cameras")时遇到问题。我的代码类似于
{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 window。我试图将 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()
关键是不要 运行 每个循环中的清除命令 (duh),这是我之前所做的,但是如果 WIDTH 和 HEIGHT 是屏幕尺寸。