Пример #1
0
    def testAnimationPlayerSlave(self):
        loop = 5
        winWidth, winHeight = 800, 600
        pygame.init()
        flags = DOUBLEBUF | OPENGL | HWPALETTE | HWSURFACE
        pygame.display.set_mode((winWidth, winHeight), flags)
        animPlayer = AnimationPlayer(framerate,
                                     self.path,
                                     self.basename, (winWidth, winHeight),
                                     loop=loop)
        glViewport(0, 0, winWidth, winHeight)  # Both required as...
        glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
        glClearColor(0, 0, 0, 1.)
        print "Rendering independently and fullscreen for %d loops." % loop
        clock = pygame.time.Clock()
        startTime = pygame.time.get_ticks()
        while not animPlayer.finished:
            ticks = clock.get_time()
            animPlayer.run(ticks)
            animPlayer.render()
            pygame.display.flip()
            clock.tick()
        stopTime = pygame.time.get_ticks()
        totalTime = stopTime - startTime
        print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
              (animPlayer.nbrFrames, loop, totalTime/1000.0,
               1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))

        # Testing animation change
        # FIXME: another set of files would be more relevant (e.g. diff. resolution)
        loop = 5
        print "Let's go for another ride of %d loops." % loop
        animPlayer.loop = loop
        animPlayer.loadAnimation(self.path, self.basename)
        startTime = pygame.time.get_ticks()
        while not animPlayer.finished:
            ticks = clock.get_time()
            animPlayer.run(ticks)
            animPlayer.render()
            pygame.display.flip()
            clock.tick()
        stopTime = pygame.time.get_ticks()
        totalTime = stopTime - startTime
        print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
              (animPlayer.nbrFrames, loop, totalTime/1000.0,
               1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))
        pygame.quit()
Пример #2
0
  def testAnimationPlayerSlave(self):
    loop = 5
    winWidth, winHeight = 800, 600
    pygame.init()
    flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
    pygame.display.set_mode((winWidth, winHeight), flags)
    animPlayer = AnimationPlayer(framerate, self.path, self.basename,
                                 (winWidth, winHeight), loop = loop)
    glViewport(0, 0, winWidth, winHeight) # Both required as...
    glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
    glClearColor(0, 0, 0, 1.)
    print "Rendering independently and fullscreen for %d loops." % loop
    clock = pygame.time.Clock()
    startTime = pygame.time.get_ticks()
    while not animPlayer.finished:
      ticks = clock.get_time()
      animPlayer.run(ticks)
      animPlayer.render()
      pygame.display.flip()
      clock.tick()
    stopTime = pygame.time.get_ticks()
    totalTime = stopTime - startTime
    print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
          (animPlayer.nbrFrames, loop, totalTime/1000.0,
           1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))

    # Testing animation change
    # FIXME: another set of files would be more relevant (e.g. diff. resolution)
    loop = 5
    print "Let's go for another ride of %d loops." % loop
    animPlayer.loop = loop
    animPlayer.loadAnimation(self.path, self.basename)
    startTime = pygame.time.get_ticks()
    while not animPlayer.finished:
      ticks = clock.get_time()
      animPlayer.run(ticks)
      animPlayer.render()
      pygame.display.flip()
      clock.tick()
    stopTime = pygame.time.get_ticks()
    totalTime = stopTime - startTime
    print "nbrFrames: %d, nbrLoops: %d, Total time: %.02f s, Average fps: %.02f" % \
          (animPlayer.nbrFrames, loop, totalTime/1000.0,
           1000.0*animPlayer.nbrFrames*(loop+1) / float(totalTime))
    pygame.quit()
Пример #3
0
    def testAnimationPlayerSlaveShowOff(self):
        winWidth, winHeight = 500, 500
        loop = 4
        pygame.init()
        flags = DOUBLEBUF | OPENGL | HWPALETTE | HWSURFACE
        pygame.display.set_mode((winWidth, winHeight), flags)
        animPlayer = AnimationPlayer(framerate,
                                     self.path,
                                     self.basename, (winWidth, winHeight),
                                     loop=loop)
        print "Rendering ourselves, doing what we want with the texture, for %d loops." % loop
        glViewport(0, 0, winWidth, winHeight)  # Both required as...
        glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
        glClearColor(0, 0, 0, 1.)
        x, y = 0.0, 1.0
        fx, fy, ftheta = 1, 1, 1
        theta = 0.0
        time = 0.0
        clock = pygame.time.Clock()
        startTime = pygame.time.get_ticks()
        while not animPlayer.finished:
            ticks = clock.get_time()
            animPlayer.run(ticks)
            texture = animPlayer.getTexture()
            # Save and clear both transformation matrices
            glMatrixMode(GL_PROJECTION)
            glPushMatrix()
            glLoadIdentity()
            glMatrixMode(GL_MODELVIEW)
            glPushMatrix()
            glLoadIdentity()

            glClear(GL_COLOR_BUFFER_BIT)
            glColor3f(1., 1., 1.)
            glBindTexture(GL_TEXTURE_2D, texture)
            glTranslatef(x, y, 0)
            glRotatef(theta, 0, 0, 1.)
            glScalef(.5, .5, 1.)
            glCallList(animPlayer.animList)

            # Restore both transformation matrices
            glPopMatrix()
            glMatrixMode(GL_PROJECTION)
            glPopMatrix()

            pygame.display.flip()

            x = (x + fx * time)
            y = (y + fy * time)
            theta = theta + ftheta
            if x > 1.0 or x < -1.0:
                fx = fx * -1
            if y > 1.0 or y < -1.0:
                fy = fy * -1
            if theta > 90 or theta < -90:
                ftheta = ftheta * -1
            time = time + 0.00001
            clock.tick(60)
        stopTime = pygame.time.get_ticks()
        totalTime = stopTime - startTime
        print "nbrFrames: %d, nbrLoops %d, Total time: %.02f s, Average fps: %.02f" % \
              (animPlayer.nbrFrames, loop, totalTime/1000.0, \
               (float(1000.0*animPlayer.nbrFrames*(loop+1)) / float(totalTime)))

        pygame.quit()
Пример #4
0
  def testAnimationPlayerSlaveShowOff(self):
    winWidth, winHeight = 500, 500
    loop = 4
    pygame.init()
    flags = DOUBLEBUF|OPENGL|HWPALETTE|HWSURFACE
    pygame.display.set_mode((winWidth, winHeight), flags)
    animPlayer = AnimationPlayer(framerate, self.path, self.basename,
                                 (winWidth, winHeight), loop = loop)
    print "Rendering ourselves, doing what we want with the texture, for %d loops." % loop
    glViewport(0, 0, winWidth, winHeight) # Both required as...
    glScissor(0, 0, winWidth, winHeight)  # ...GameEngine changes it
    glClearColor(0, 0, 0, 1.)
    x, y = 0.0, 1.0
    fx, fy, ftheta = 1, 1, 1
    theta = 0.0
    time = 0.0
    clock = pygame.time.Clock()
    startTime = pygame.time.get_ticks()
    while not animPlayer.finished:
      ticks = clock.get_time()
      animPlayer.run(ticks)
      texture = animPlayer.getTexture()
      # Save and clear both transformation matrices
      glMatrixMode(GL_PROJECTION)
      glPushMatrix()
      glLoadIdentity()
      glMatrixMode(GL_MODELVIEW)
      glPushMatrix()
      glLoadIdentity()

      glClear(GL_COLOR_BUFFER_BIT)
      glColor3f(1., 1., 1.)
      glBindTexture(GL_TEXTURE_2D, texture)
      glTranslatef(x, y, 0)
      glRotatef(theta, 0, 0, 1.)
      glScalef(.5, .5, 1.)
      glCallList(animPlayer.animList)

      # Restore both transformation matrices
      glPopMatrix()
      glMatrixMode(GL_PROJECTION)
      glPopMatrix()

      pygame.display.flip()

      x = (x + fx*time)
      y = (y + fy*time)
      theta = theta + ftheta
      if x > 1.0 or x < -1.0:
        fx = fx * -1
      if y > 1.0 or y < -1.0:
        fy = fy * -1
      if theta > 90 or theta < -90:
        ftheta = ftheta * -1
      time = time + 0.00001
      clock.tick(60)
    stopTime = pygame.time.get_ticks()
    totalTime = stopTime - startTime
    print "nbrFrames: %d, nbrLoops %d, Total time: %.02f s, Average fps: %.02f" % \
          (animPlayer.nbrFrames, loop, totalTime/1000.0, \
           (float(1000.0*animPlayer.nbrFrames*(loop+1)) / float(totalTime)))
    
    pygame.quit()