Skip to main content

A ctypes-based wrapper for GLFW3.

Project description

This module provides Python bindings for GLFW (on GitHub: glfw/glfw). It is a ctypes wrapper which keeps very close to the original GLFW API, except for:

  • function names use the pythonic words_with_underscores notation instead of camelCase

  • GLFW_ and glfw prefixes have been removed, as their function is replaced by the module namespace (you can use from glfw.GLFW import * if you prefer the naming convention used by the GLFW C API)

  • structs have been replaced with Python sequences and namedtuples

  • functions like glfwGetMonitors return a list instead of a pointer and an object count

  • Gamma ramps use floats between 0.0 and 1.0 instead of unsigned shorts (use glfw.NORMALIZE_GAMMA_RAMPS=False to disable this)

  • GLFW errors are reported as glfw.GLFWError warnings if no error callback is set (use glfw.ERROR_REPORTING=False to disable this, set it to ‘warn’ instead to issue warnings, set it to ‘log’ to log it using the ‘glfw’ logger or set it to a dict to define the behavior for specific error codes)

  • instead of a sequence for GLFWimage structs, PIL/pillow Image objects can be used

Installation

pyGLFW can be installed using pip:

pip install glfw

Windows

The GLFW shared library and Visual C++ runtime are included in the Python wheels.

To use a different GLFW library, you can set PYGLFW_LIBRARY to its location.

macOS

The GLFW shared library for 64-bit is included in the Python wheels for macOS.

If you are using a 32-bit Python installation or otherwise cannot use the library downloaded with the wheel, you can build and install it yourself by compiling GLFW from source (use -DBUILD_SHARED_LIBS=ON).

pyGLFW will search for the library in a list of search paths (including those in DYLD_LIBRARY_PATH). If you want to use a specific library, you can set the PYGLFW_LIBRARY environment variable to its path.

Linux

The GLFW shared library is included in the Python wheels for Linux. Although pyGLFW will try to detect whether the GLFW library for Wayland or X11 should be used, you can set the PYGLFW_LIBRARY_VARIANT variable to wayland or x11 to select either variant of the library.

If you cannot use these on your system, you can install the GLFW shared library using a package management system (e.g. apt install libglfw3 on Debian or Ubuntu) or you can build and install it yourself by compiling GLFW from source (use -DBUILD_SHARED_LIBS=ON).

pyGLFW will search for the library in a list of search paths (including those in LD_LIBRARY_PATH). If you want to use a specific library, you can set the PYGLFW_LIBRARY environment variable to its path.

cx_Freeze / PyInstaller

pyGLFW will search for the GLFW library in the current working directory, the directory of the executable and in the package on non-Windows platforms if running in an executable frozen with cx_Freeze or PyInstaller, unless the PYGLFW_LIBRARY environment variable is set.

Development Version

If you are using the development version of GLFW and would like to use wrappers for currently unreleased macros and functions, you can instead install:

pip install glfw[preview]

or set the PYGLFW_PREVIEW environment variable.

Note, however, that there will be a slight delay between the development version of GLFW and the wrappers provided by this package.

Example Code

The example from the GLFW documentation ported to pyGLFW:

import glfw

def main():
    # Initialize the library
    if not glfw.init():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.create_window(640, 480, "Hello World", None, None)
    if not window:
        glfw.terminate()
        return

    # Make the window's context current
    glfw.make_context_current(window)

    # Loop until the user closes the window
    while not glfw.window_should_close(window):
        # Render here, e.g. using pyOpenGL

        # Swap front and back buffers
        glfw.swap_buffers(window)

        # Poll for and process events
        glfw.poll_events()

    glfw.terminate()

if __name__ == "__main__":
    main()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glfw-2.10.1.tar.gz (36.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

glfw-2.10.1-py2.py3-none-win_amd64.whl (564.4 kB view details)

Uploaded Python 2Python 3Windows x86-64

glfw-2.10.1-py2.py3-none-win32.whl (557.6 kB view details)

Uploaded Python 2Python 3Windows x86

glfw-2.10.1-py2.py3-none-manylinux_2_28_x86_64.whl (248.5 kB view details)

Uploaded Python 2Python 3manylinux: glibc 2.28+ x86-64

glfw-2.10.1-py2.py3-none-manylinux_2_28_aarch64.whl (236.0 kB view details)

Uploaded Python 2Python 3manylinux: glibc 2.28+ ARM64

glfw-2.10.1-py2.py3-none-manylinux2014_x86_64.whl (246.9 kB view details)

Uploaded Python 2Python 3

glfw-2.10.1-py2.py3-none-manylinux2014_aarch64.whl (235.0 kB view details)

Uploaded Python 2Python 3

glfw-2.10.1-py2.py3-none-macosx_11_0_arm64.whl (107.1 kB view details)

Uploaded Python 2Python 3macOS 11.0+ ARM64

glfw-2.10.1-py2.py3-none-macosx_10_6_intel.whl (110.3 kB view details)

Uploaded Python 2Python 3macOS 10.6+ Intel (x86-64, i386)

File details

Details for the file glfw-2.10.1.tar.gz.

File metadata

  • Download URL: glfw-2.10.1.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for glfw-2.10.1.tar.gz
Algorithm Hash digest
SHA256 aceb1d3e37aa5e5f8facffe75223ea1f12f595b78120f436982dfc61e7d7973c
MD5 a674222cc41dca472fd7ed21baee8081
BLAKE2b-256 740146074a3f6085bdd91e232da80dff79ca2b0b6beb5dd62dbe9be49830cb41

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-win_amd64.whl.

File metadata

  • Download URL: glfw-2.10.1-py2.py3-none-win_amd64.whl
  • Upload date:
  • Size: 564.4 kB
  • Tags: Python 2, Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for glfw-2.10.1-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 757e8df8db60994a33d5e5b16a5c12e81ccdcd20842faf5e9dcabb5c5115ee19
MD5 9f44b129b2dfc4aaf0193b2dcb223457
BLAKE2b-256 a8f3f42facc0a2c786604300ba4bb566295f623f166c65818cade89f69efa8ca

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-win32.whl.

File metadata

  • Download URL: glfw-2.10.1-py2.py3-none-win32.whl
  • Upload date:
  • Size: 557.6 kB
  • Tags: Python 2, Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for glfw-2.10.1-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 bbaebf066f509ec5bbf7d1e1614a2d33c43ab96b520764635a132422ee90a846
MD5 f6f366ca85bcf9a8210992eb5ab6fb48
BLAKE2b-256 9ca13bb668375916b7438172957767a277b0568af9acb73c22a617088cb2f3d2

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glfw-2.10.1-py2.py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a58e414a44996731629235eb7c85795100bc4d5eec657da789788a1284b94f62
MD5 5c49b5fe9c1a5c38044cca13c6b30cb9
BLAKE2b-256 a2d90587c7aa21929eb5a35cf26570689416eece174cdc8d4235a611b7cd382e

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for glfw-2.10.1-py2.py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dc5fc94a9124072c08539de16649026b90c119c12c6d4e860f10d578d2f2185c
MD5 65a10e802c6a1cc304fdd6ff5753a15a
BLAKE2b-256 f84a43ff410672cc0befcb9966df555bd71f9da30eaff839e9916d40080b5a90

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glfw-2.10.1-py2.py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e032324ae5e431d877ec46fb2ef5ae1d4ca76cfcb9ed60bfef5b6fc42638bda2
MD5 b5be1d11cc8e37eae65ad165c062e82d
BLAKE2b-256 60bc04b51868959611aa3aea07774d525019ef73ab302e969881b096f1184535

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for glfw-2.10.1-py2.py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c0e4c01b9ea1f00620f89882840a10f64fb91d6a5f1596a615ba76bc8aae5c6a
MD5 960735050e524abc20faa6f724f16b53
BLAKE2b-256 bd0086e30f858823797ee64dfeb6834aa0151a041d22c273879ced0413791e6f

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for glfw-2.10.1-py2.py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5686b609ab45a2439c65486c8715a97eb08643b71a25c93d127f073e852fe766
MD5 c2b891fdfc17e5ee0d42c0c4dfe4bbdf
BLAKE2b-256 fd92fcc208182cbad5a15894fde0ccd34c324a8eff53bad3c9975be92ad18ba6

See more details on using hashes here.

File details

Details for the file glfw-2.10.1-py2.py3-none-macosx_10_6_intel.whl.

File metadata

  • Download URL: glfw-2.10.1-py2.py3-none-macosx_10_6_intel.whl
  • Upload date:
  • Size: 110.3 kB
  • Tags: Python 2, Python 3, macOS 10.6+ Intel (x86-64, i386)
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for glfw-2.10.1-py2.py3-none-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 cc8033d8b5d9e600316d05c78e0d541447ed5dc3abd7a4e9d695c0292ee3cda1
MD5 2cb64bd2a1eb177fd7a7cf55f4db3b36
BLAKE2b-256 37136d6b818d79c5b4002b905a33dfd1ee0cbeeece6c0be47e5baa090ebd13c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page