2013-06-21 43 views
0

我必须评估Pyopengl vs Pyglet的性能/功能。主要关注的是它在使用高FPS时不会掉帧。在我开始学习之前,我需要看看它是否能够满足客户的需求。Python:pyglet vs PyOpengl丢帧性能评估

我想在红色和绿色(全屏模式)之间交替(在vsync上)。如果有人能给我一个很好的教程网站,或者帮助我一个例子,这将是非常好的。

我已经看过这个帖子(及以上): FPS with Pyglet half of monitor refresh rate

进行了修改,但不能看到如何从一种颜色切换到上垂直同步另一个。

import pyglet 
from pyglet.gl import * 


fps = pyglet.clock.ClockDisplay() 

# The game window 
class Window(pyglet.window.Window): 
    def __init__(self): 
     super(Window, self).__init__(fullscreen=True, vsync = False) 
     self.flipScreen = 0 
     glClearColor(1.0, 1.0, 1.0, 1.0) 
     # Run "self.update" 128 frames a second and set FPS limit to 128. 
     pyglet.clock.schedule_interval(self.update, 1.0/128.0) 
     pyglet.clock.set_fps_limit(128) 


def update(self, dt): 
    self.flipScreen = not self.flipScreen 
    pass 

def on_draw(self): 
    pyglet.clock.tick() # Make sure you tick the clock! 
    if self.flipScreen == 0: 
     glClearColor(0, 1, 0, 1.0) 
    else: 
     glClearColor(1, 0, 0, 1.0) 
    self.clear() 
    fps.draw() 

# Create a window and run 
win = Window() 
pyglet.app.run() 

我看过很多教程,但是我一直无法理解如何运行这一个测试。

感谢您的帮助。

回答

0

这是一个代码,它使用pyglet。它已经在3个监视器上以60Hz和120Hz进行了测试。请注意,使用全局变量是不好的。它可能不是很干净,但它清楚地表明考虑了vsync。这是代码测试vsync功能的目的。

import pyglet 
from pyglet.gl import * 
from OpenGL.GL import * 
from OpenGL.GLUT import * 
from OpenGL.GLU import * 

# Direct OpenGL commands to this window. 
config = Config(double_buffer = True) 
window = pyglet.window.Window(config = config) 
window.set_vsync(True) 
window.set_fullscreen(True) 

colorSwap = 0 
fullscreen = 1 

fps_display = pyglet.clock.ClockDisplay() 

def on_draw(dt): 
    global colorSwap 
    glClear(GL_COLOR_BUFFER_BIT) # Clear the color buffer 
    glLoadIdentity()    # Reset model-view matrix 

    glBegin(GL_QUADS) 
    if colorSwap == 1: 
     glColor3f(1.0, 0.0, 0.0) 
     colorSwap = 0 
    else: 
     glColor3f(0.0, 1.0, 0.0) 
     colorSwap = 1 

    glVertex2f(window.width, 0) 
    glVertex2f(window.width, window.height) 
    glVertex2f(0.0, window.height) 
    glVertex2f(0.0, 0.0) 
    glEnd() 
    fps_display.draw() 

@window.event 
def on_key_press(symbol, modifiers): 
    global fullscreen 
    if symbol == pyglet.window.key.F: 
     if fullscreen == 1: 
      window.set_fullscreen(False) 
      fullscreen = 0 
     else: 
      window.set_fullscreen(True) 
      fullscreen = 1 
    elif symbol == pyglet.window.key.ESCAPE: 
     print ''   


dt = pyglet.clock.tick() 
pyglet.clock.schedule_interval(on_draw, 0.0001) 
pyglet.app.run()