示例#1
0
 def reshape(self,  w, h):
        GL.glViewport( 0, 0, w, h)
        GL.glMatrixMode( GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GL.glFrustum( -1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
        GL.glMatrixMode( GL.GL_MODELVIEW)
   def beginTile(self):

      if self.CurrentTile <= 0:
         self.setup()
      # Save user's viewport, will be restored after last tile rendered
      self.ViewportSave = GL.glGetIntegerv(GL.GL_VIEWPORT)

      # which tile (by row and column) we're about to render
      if self.RowOrder==TR_BOTTOM_TO_TOP:
         self.CurrentRow = self.CurrentTile / self.Columns
         self.CurrentColumn = self.CurrentTile % self.Columns
      elif self.RowOrder==TR_TOP_TO_BOTTOM:
         self.CurrentRow = self.Rows - (self.CurrentTile / self.Columns) - 1
         self.CurrentColumn = self.CurrentTile % self.Columns
      else:
         raise RuntimeError

      assert(self.CurrentRow < self.Rows)
      assert(self.CurrentColumn < self.Columns)

      border = self.TileBorder

      # Compute actual size of this tile with border
      if self.CurrentRow < self.Rows-1:
         tileHeight = self.TileHeight
      else:
         tileHeight = self.ImageHeight - (self.Rows-1) * \
                      (self.TileHeightNB) + 2 * border

      if self.CurrentColumn < self.Columns-1:
         tileWidth = self.TileWidth
      else:
         tileWidth = self.ImageWidth - (self.Columns-1) * \
                     (self.TileWidthNB) + 2 * border

      # Save tile size, with border
      self.CurrentTileWidth = tileWidth
      self.CurrentTileHeight = tileHeight

      GL.glViewport(0, 0, tileWidth, tileHeight) #tile size including border

      # save current matrix mode
      matrixMode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)[0]
      GL.glMatrixMode(GL.GL_PROJECTION)
      GL.glLoadIdentity()

      # compute projection parameters
      self.tileleft = left = self.Left + (self.Right - self.Left) \
                      * (self.CurrentColumn * self.TileWidthNB - border) \
                      / self.ImageWidth
      self.tileright = right = left + (self.Right - self.Left) * \
                       self.TileWidth / self.ImageWidth
      self.tilebottom = bottom = self.Bottom + (self.Top - self.Bottom) \
                        * (self.CurrentRow * self.TileHeightNB - border) / \
                        self.ImageHeight
      self.tiletop = top = bottom + (self.Top - self.Bottom) * self.TileHeight / \
                     self.ImageHeight

      if self.Perspective:
         GL.glFrustum(float(left), float(right),
                      float(bottom), float(top),
                      float(self.Near), float(self.Far))
      else:
         GL.glOrtho(float(left), float(right),
                    float(bottom), float(top),
                    float(self.Near), float(self.Far))

      # restore user's matrix mode
      GL.glMatrixMode(int(matrixMode))
示例#3
0
    def beginTile(self):

        if self.CurrentTile <= 0:
            self.setup()
        # Save user's viewport, will be restored after last tile rendered
        self.ViewportSave = GL.glGetIntegerv(GL.GL_VIEWPORT)

        # which tile (by row and column) we're about to render
        if self.RowOrder == TR_BOTTOM_TO_TOP:
            self.CurrentRow = self.CurrentTile / self.Columns
            self.CurrentColumn = self.CurrentTile % self.Columns
        elif self.RowOrder == TR_TOP_TO_BOTTOM:
            self.CurrentRow = self.Rows - (self.CurrentTile / self.Columns) - 1
            self.CurrentColumn = self.CurrentTile % self.Columns
        else:
            raise RuntimeError

        assert (self.CurrentRow < self.Rows)
        assert (self.CurrentColumn < self.Columns)

        border = self.TileBorder

        # Compute actual size of this tile with border
        if self.CurrentRow < self.Rows - 1:
            tileHeight = self.TileHeight
        else:
            tileHeight = self.ImageHeight - (self.Rows-1) * \
                         (self.TileHeightNB) + 2 * border

        if self.CurrentColumn < self.Columns - 1:
            tileWidth = self.TileWidth
        else:
            tileWidth = self.ImageWidth - (self.Columns-1) * \
                        (self.TileWidthNB) + 2 * border

        # Save tile size, with border
        self.CurrentTileWidth = tileWidth
        self.CurrentTileHeight = tileHeight

        GL.glViewport(0, 0, tileWidth, tileHeight)  #tile size including border

        # save current matrix mode
        matrixMode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)[0]
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()

        # compute projection parameters
        self.tileleft = left = self.Left + (self.Right - self.Left) \
                        * (self.CurrentColumn * self.TileWidthNB - border) \
                        / self.ImageWidth
        self.tileright = right = left + (self.Right - self.Left) * \
                         self.TileWidth / self.ImageWidth
        self.tilebottom = bottom = self.Bottom + (self.Top - self.Bottom) \
                          * (self.CurrentRow * self.TileHeightNB - border) / \
                          self.ImageHeight
        self.tiletop = top = bottom + (self.Top - self.Bottom) * self.TileHeight / \
                       self.ImageHeight

        if self.Perspective:
            GL.glFrustum(float(left), float(right), float(bottom), float(top),
                         float(self.Near), float(self.Far))
        else:
            GL.glOrtho(float(left), float(right), float(bottom), float(top),
                       float(self.Near), float(self.Far))

        # restore user's matrix mode
        GL.glMatrixMode(int(matrixMode))
示例#4
0
GLUT.glutInit (sys.argv)
GLUT.glutInitDisplayMode (GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH)
GLUT.glutCreateWindow ("join styles")
GLUT.glutDisplayFunc (DrawStuff)
#GLUT.glutMotionFunc (MouseMotion)


#    initialize GL 
GL.glClearDepth (1.0)
GL.glEnable (GL.GL_DEPTH_TEST)
GL.glClearColor (0.0, 0.0, 0.0, 0.0)
GL.glShadeModel (GL.GL_SMOOTH)

GL.glMatrixMode (GL.GL_PROJECTION)
# roughly, measured in centimeters 
GL.glFrustum (-9.0, 9.0, -9.0, 9.0, 50.0, 150.0)
GL.glMatrixMode(GL.GL_MODELVIEW)

# initialize lighting 
GL.glLightfv (GL.GL_LIGHT0, GL.GL_POSITION, lightOnePosition)
GL.glLightfv (GL.GL_LIGHT0, GL.GL_DIFFUSE, lightOneColor)
GL.glEnable (GL.GL_LIGHT0)
GL.glLightfv (GL.GL_LIGHT1, GL.GL_POSITION, lightTwoPosition)
GL.glLightfv (GL.GL_LIGHT1, GL.GL_DIFFUSE, lightTwoColor)
GL.glEnable (GL.GL_LIGHT1)
GL.glEnable (GL.GL_LIGHTING)
GL.glEnable (GL.GL_NORMALIZE)
GL.glColorMaterial (GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE)
GL.glEnable (GL.GL_COLOR_MATERIAL)

InitStuff ()