Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 一个Pyglet窗口上有多个视口?_Python_Opengl_Pyglet - Fatal编程技术网

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

Python 一个Pyglet窗口上有多个视口?,python,opengl,pyglet,Python,Opengl,Pyglet,我需要在python Pyglet中创建多维数据集的多个视口,但我总是只有一个 查看“调整大小”上的def: 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 de

我需要在python Pyglet中创建多维数据集的多个视口,但我总是只有一个

查看“调整大小”上的def:

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()
立方体图

        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()

您能帮助解决这个问题吗?

设置视口和矩阵将修改OpenGL状态。你必须在那之后画些东西。设置新视口只会覆盖以前的设置。比如:

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

以下是OpenGL初学者的一般提示/提示/规则,他们正在努力解决以下问题:


在学习过程中,不要在绘图函数之外调用OpenGL!设置矩阵、视口等,并始终进入绘图功能。

如何调用绘图功能?如果我创建单独的函数来绘制立方体,立方体不会移动、旋转或缩放,我需要做这些事情,它只有在绘制完整代码时才起作用,所以你可以正确理解我,所有的绘制都应该在绘制中进行。这里的代码应该正好在那里。谢谢,这很有效,你知道如何制作不同的正交投影吗?我从前面做了一个,我还需要从侧面做一个,使用modelview矩阵相应地旋转立方体。