Beispiel #1
0
def window_space(win):
    modelview_mat = bgl.Buffer(bgl.GL_DOUBLE, 16)
    projection_mat = bgl.Buffer(bgl.GL_DOUBLE, 16)
    bgl.glGetDoublev(bgl.GL_MODELVIEW_MATRIX, modelview_mat)
    bgl.glGetDoublev(bgl.GL_PROJECTION_MATRIX, projection_mat)

    matrix_mode = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_MATRIX_MODE, matrix_mode)

    viewport = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport)

    bgl.glViewport(0, 0, win.width, win.height)
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    ofs = -0.01
    bgl.glOrtho(ofs, win.width + ofs, ofs, win.height + ofs, -100, 100)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    bgl.glMatrixMode(matrix_mode[0])

    yield

    bgl.glViewport(*viewport)

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadMatrixd(projection_mat)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadMatrixd(modelview_mat)
    bgl.glMatrixMode(matrix_mode[0])
Beispiel #2
0
def window_space(win):
    modelview_mat = bgl.Buffer(bgl.GL_DOUBLE, 16)
    projection_mat = bgl.Buffer(bgl.GL_DOUBLE, 16)
    bgl.glGetDoublev(bgl.GL_MODELVIEW_MATRIX, modelview_mat)
    bgl.glGetDoublev(bgl.GL_PROJECTION_MATRIX, projection_mat)

    matrix_mode = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_MATRIX_MODE, matrix_mode)

    viewport = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport)

    bgl.glViewport(0, 0, win.width, win.height)
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    ofs = -0.01
    bgl.glOrtho(ofs, win.width + ofs, ofs, win.height + ofs, -100, 100)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    bgl.glMatrixMode(matrix_mode[0])

    yield

    bgl.glViewport(*viewport)

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadMatrixd(projection_mat)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadMatrixd(modelview_mat)
    bgl.glMatrixMode(matrix_mode[0])
Beispiel #3
0
 def mul_4x4_matrixd(m1, m2):
     """double型で大きさが16のBuffer同士の積"""
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)  # GL_MAX_MODELVIEW_STACK_DEPTH: 32
     bgl.glPushMatrix()
     bgl.glLoadMatrixd(m1)
     bgl.glMultMatrixd(m2)
     mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
     bgl.glPopMatrix()
     bgl.glMatrixMode(matrix_mode)
     return mat
Beispiel #4
0
 def mul_4x4_matrixd(m1, m2):
     """double型で大きさが16のBuffer同士の積"""
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)  # GL_MAX_MODELVIEW_STACK_DEPTH: 32
     bgl.glPushMatrix()
     bgl.glLoadMatrixd(m1)
     bgl.glMultMatrixd(m2)
     mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
     bgl.glPopMatrix()
     bgl.glMatrixMode(matrix_mode)
     return mat
Beispiel #5
0
 def _load_matrix(cls, modelview=None, projection=None):
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     if modelview:
         bgl.glMatrixMode(bgl.GL_MODELVIEW)
         bgl.glLoadIdentity()  # glLoadMatrix()にも必須
         if isinstance(modelview, bgl.Buffer):
             bgl.glLoadMatrixd(modelview)
     if projection:
         bgl.glMatrixMode(bgl.GL_PROJECTION)
         bgl.glLoadIdentity()  # glLoadMatrix()にも必須
         if isinstance(projection, bgl.Buffer):
             bgl.glLoadMatrixd(projection)
     bgl.glMatrixMode(matrix_mode)
Beispiel #6
0
 def _load_matrix(self, modelview=None, projection=None):
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     if modelview:
         bgl.glMatrixMode(bgl.GL_MODELVIEW)
         bgl.glLoadIdentity()  # glLoadMatrix()にも必須
         if isinstance(modelview, bgl.Buffer):
             bgl.glLoadMatrixd(modelview)
     if projection:
         bgl.glMatrixMode(bgl.GL_PROJECTION)
         bgl.glLoadIdentity()  # glLoadMatrix()にも必須
         if isinstance(projection, bgl.Buffer):
             bgl.glLoadMatrixd(projection)
     bgl.glMatrixMode(matrix_mode)