【问题标题】:Python: pyglet vs PyOpengl performance evaluation for frame droppingPython:用于丢帧的 pyglet 与 PyOpengl 性能评估
【发布时间】:2013-06-18 14:17:20
【问题描述】:

我必须评估 Pyopengl 与 Pyglet 的性能/功能。主要问题是它在使用高 FPS 时不会丢帧。在我开始学习其中之一之前,我需要看看它是否可以满足客户的需求。

我正在尝试在红色和绿色之间(在全屏模式下)交替(在垂直同步上)。如果有人能给我一个很好的教程网站,或者帮我举个例子,那就太好了。

我看过这篇文章(以及更多): FPS with Pyglet half of monitor refresh rate

进行了修改,但在 Vsync 上看不到如何从一种颜色切换到另一种颜色。

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

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

感谢您的帮助。

【问题讨论】:

    标签: python pyglet pyopengl


    【解决方案1】:

    这是一个使用 pyglet 的代码。它已经在 3 个 60 Hz 和 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()
    

    【讨论】:

      猜你喜欢
      • 2010-09-21
      • 1970-01-01
      • 2020-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多