No description
  • C 52.7%
  • Makefile 42.1%
  • Shell 5.2%
Find a file
2026-04-23 12:58:41 +02:00
.gitignore Initial commit: fpslimit, Makefile, README, LICENSE 2026-04-23 12:57:09 +02:00
fpslimit.c Initial commit: fpslimit, Makefile, README, LICENSE 2026-04-23 12:57:09 +02:00
fpslimit.sh Initial commit: fpslimit, Makefile, README, LICENSE 2026-04-23 12:57:09 +02:00
LICENSE typo 2026-04-23 12:58:41 +02:00
Makefile Initial commit: fpslimit, Makefile, README, LICENSE 2026-04-23 12:57:09 +02:00
README.md Initial commit: fpslimit, Makefile, README, LICENSE 2026-04-23 12:57:09 +02:00

fpslimit

Minimal FPS limiter for OpenGL applications on Linux.

What it does

fpslimit is a small shared library that gets injected into OpenGL programs via LD_PRELOAD. It intercepts calls to glXSwapBuffers and, after each rendered frame, sleeps the remaining time up to the target frame duration, preventing the program from running faster than the configured framerate.

Useful for example when

  • a program runs in a VM without working VSync and wastes CPU cycles,
  • you want to simulate the behavior of a display with a fixed refresh rate,
  • you want to cap benchmark tools or demos at a fixed rate.

The target framerate is configured in the source code via target_ns (default: 30 FPS, i.e. 33333333 nanoseconds).

Requirements

To build, you need:

  • gcc (or another C compiler)
  • libc6-dev standard C headers
  • libgl-dev OpenGL/GLX headers (GL/glx.h)
  • make (optional, for convenience)

On Debian / Ubuntu / Xubuntu, install everything at once with:

sudo apt install build-essential libgl-dev

Build and install

git clone https://git.schwarz.dev/ralf/fpslimit.git
cd fpslimit
make
sudo make install

The library is installed to /usr/local/lib/fpslimit/fpslimit.so and the wrapper script to /usr/local/bin/fpslimit. A different target prefix can be set via PREFIX, e.g. sudo make install PREFIX=/opt/fpslimit.

Usage

fpslimit glxgears

Works with any OpenGL program that uses glXSwapBuffers:

fpslimit glmark2
fpslimit myprogram

Changing the framerate

The target framerate is hardcoded in the source. Edit the line

const long target_ns = 33333333L; // 1/30 s

in fpslimit.c. Common values:

  • 60 FPS → 16666667L
  • 30 FPS → 33333333L
  • 24 FPS → 41666667L

Then rebuild and reinstall:

make clean
make
sudo make install

Uninstall

sudo make uninstall

Removes /usr/local/bin/fpslimit and /usr/local/lib/fpslimit/.

Manual build without Makefile

If make is not available:

gcc -shared -fPIC -O2 -o fpslimit.so fpslimit.c -ldl

The result can be used directly via LD_PRELOAD:

LD_PRELOAD=./fpslimit.so glxgears

Limitations

  • Only affects programs that use GLX (glXSwapBuffers). For EGL-based applications (Wayland-only, GLES), eglSwapBuffers would need to be hooked as well.
  • The target framerate is set at compile time; no runtime configuration.

License

MIT see LICENSE.