简体   繁体   English

一个Pyglet窗口上有多个视口?

[英]Multiple viewports on one Pyglet window?

I need to make mutiple viewports of cube in python Pyglet, but i always just have one. 我需要在python Pyglet中制作多维数据集的多维数据集视口,但我总是只有一个。

Look at def on_resize(): 看一下def on_resize():

WINDOW = 1000 
INCREMENT = 5
transparant = False

class Window(pyglet.window.Window):
    xRotation = yRotation = zRotation = 30
    zoom = 1
    far = 100
    dist = 35
    x = y = z = 0

    def __init__(self, width, height, title = '') :
        super(Window, self).__init__( 1300,1000, title)
        pgl.glClearColor(0, 0, 0, 1)
        pgl.glEnable(pgl.GL_DEPTH_TEST)



    def on_draw(self) :

        self.clear()

cube drawing 立方体图

        pgl.glPopMatrix()

    def on_resize(self, width, height) :
        pgl.glClear(pgl.GL_COLOR_BUFFER_BIT | pgl.GL_DEPTH_BUFFER_BIT)

        pgl.glViewport(0, 0, 650, 500)
        pgl.glLoadIdentity()
        pgl.glMatrixMode(ogl.GL_PROJECTION)
        pgl.glOrtho(-width / 8, width / 8, -height / 8, height / 8, 0, 500)
        pgl.glFlush()

        pgl.glViewport(500, 0, 650, 500)
        pgl.glLoadIdentity()
        pgl.glMatrixMode(ogl.GL_PROJECTION)
        Ratio = width/height
        # pgl.gluPerspective(self.dist, Ratio, 1, 1000)
        pgl.glOrtho(-width/8, width/8, -height/8, height/8, 0, 500)
        pgl.glFlush()
        pgl.glMatrixMode(ogl.GL_MODELVIEW)
        pgl.glTranslatef(0, 0, -100)

Window(WINDOW, WINDOW, 'Cube')
pyglet.app.run()

Can you help to solve this problem? 您能帮助解决这个问题吗?

Setting the viewport and matrices will modify OpenGL state. 设置视口和矩阵将修改OpenGL状态。 You have to draw something right after that. 之后,您必须立即画些东西。 Setting a new viewport will just override the previous setting. 设置新的视口将覆盖先前的设置。 Something like: 就像是:

pgl.glClear(pgl.GL_COLOR_BUFFER_BIT | pgl.GL_DEPTH_BUFFER_BIT)

pgl.glViewport(0, 0, 650, 500)    
pgl.glMatrixMode(ogl.GL_PROJECTION)
pgl.glLoadIdentity()
pgl.glOrtho(-width / 8, width / 8, -height / 8, height / 8, 0, 500)
pgl.glMatrixMode(ogl.GL_MODELVIEW)
# set modelview matrix
# draw cube

pgl.glViewport(500, 0, 650, 500)
pgl.glMatrixMode(ogl.GL_PROJECTION)
pgl.glLoadIdentity()
# this is actually the same as before, so you can just leave it
pgl.glOrtho(-width/8, width/8, -height/8, height/8, 0, 500)
pgl.glMatrixMode(ogl.GL_MODELVIEW)
pgl.glTranslatef(0, 0, -100)
# set modelview matrix
# draw cube

Here's a general tip/hint/rule for OpenGL beginners, struggling with these kinds of problems: 这是针对此类问题的OpenGL初学者的一般提示/提示/规则:

While you're learning, make no OpenGL calls outside the drawing function ! 在学习时,请不要在绘图功能之外进行OpenGL调用 Setting up matrices, the viewport and so and always goes into the drawing function. 设置矩阵,视口等总是进入绘图功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM