Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run pyglet at more than 60fps?

Tags:

python

pyglet

I've been trying to make an environment and want to run it as fast as possible (1000+ FPS if possible). I tried experimenting with pyglet, and it seems as though I cannot go beyond 60fps.

I used the following setting to call my update function

pyglet.clock.schedule_interval(update, 1.0/120.0)

The environment currently has just 1 sprite, and there is no expensive computation that is happening. Running just the update method for 1000 iterations takes 2ms.

It seems to work okay if I reduce the FPS, but always gets capped at 60FPS. Is there any way around this?

like image 594
Praveen Venkatesh Avatar asked Oct 27 '25 15:10

Praveen Venkatesh


1 Answers

From Migrating from pyglet 1.5:

Application Event Loop
^^^^^^^^^^^^^^^
In previous releases, the Window was redrawn (and the Window.on_draw() event dispatched) whenever any scheduled function was called, or event dispatched. This often lead to unpredictability and potentially unstable frame rates. In pyglet 2.0, a new interval argument has been added to pyglet.app.run. Windows will now always be redrawn at this interval. It defaults to 60fps > (1/60), but can be set as desired:

@mywindow.event
def on_draw():
    # always called at 120fps

pyglet.app.run(interval=1/120)

Other things to keep in mind:

https://pyglet.readthedocs.io/en/latest/programming_guide/time.html

Periodic Events

You can schedule updates on an interval. This is for ideal for animation, physics simulation, and game state updates.

pyglet.clock.schedule_interval(update, 1 / 60.0)

Or, if you want to call the function as frequently as possible:

pyglet.clock.schedule(benchmark)

Vsync

Pyglet window buffer swaps are synchronized to the display refresh rate, so you may want to disable vsync. This can specified at window creation time or set with window.set_vsync(False)

like image 57
Dragonflii Avatar answered Oct 30 '25 06:10

Dragonflii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!