简体   繁体   中英

Multiple viewports on one Pyglet window?

I need to make mutiple viewports of cube in python Pyglet, but i always just have one.

Look at 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. 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:

While you're learning, make no OpenGL calls outside the drawing function ! Setting up matrices, the viewport and so and always goes into the drawing function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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