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.2.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.2-py2.py3-none-win_amd64.whl (564.4 kB view details)

Uploaded Python 2Python 3Windows x86-64

glfw-2.10.2-py2.py3-none-win32.whl (557.7 kB view details)

Uploaded Python 2Python 3Windows x86

glfw-2.10.2-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.2-py2.py3-none-manylinux_2_28_aarch64.whl (236.0 kB view details)

Uploaded Python 2Python 3manylinux: glibc 2.28+ ARM64

glfw-2.10.2-py2.py3-none-manylinux2014_x86_64.whl (247.0 kB view details)

Uploaded Python 2Python 3

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

Uploaded Python 2Python 3

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

Uploaded Python 2Python 3macOS 11.0+ ARM64

glfw-2.10.2-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.2.tar.gz.

File metadata

  • Download URL: glfw-2.10.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5d2cf97c66bc42a6b583be0e307eae5a3945438322e2ed0c5e4f14dc251d693d
MD5 1dec8678dff2ff3c4636048484b8afae
BLAKE2b-256 0f62096058bcb4b4fb28f7ecd28fb048f07969d90b243c417af5f6d09d45a0c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glfw-2.10.2-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.2-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 15fd0666cd8f1b0ecb535c3abb712b8ddda053bf8d16de2353b1c6ced0e65402
MD5 8ccf10f173fa2d556a3f9476d68fd20f
BLAKE2b-256 e06c4ca5f3ab85a8d7f612ce857208726e9b834e54e559751e3d4f98cc2f7509

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glfw-2.10.2-py2.py3-none-win32.whl
  • Upload date:
  • Size: 557.7 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.2-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 a94aefe8c48886fd83cd6e11e936846166a4b5b94abf1f4bf599d984774b0b1b
MD5 216250088609a93f9ffa548f18f16adc
BLAKE2b-256 12d9bd2e6c8dbadcf69fcd2289705e75881258b46221c196903a52e9f6e97322

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glfw-2.10.2-py2.py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b860de3ca0686182483f98f3ddd12e660acf25b3e0d521450ec9a3f999f72a65
MD5 0b1674d6b8ae6c72d79674f48bc73246
BLAKE2b-256 69841b98671314ea5f40397586b6cd14db913de3196333be558fdc177e61708f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glfw-2.10.2-py2.py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7604425ec95665cc6a25c3ed7d07e9660d394a34472ceffaec0843c844e7b649
MD5 9c1845a92f707068cd69bf3b5e872ddf
BLAKE2b-256 52fc29b4f1a8c8e33d8934781330a0845458b01da7f389d9fe6a3350e752b7f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glfw-2.10.2-py2.py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82daf1f87b2a48815637dc6f6720d4a55a57ba1d3683322dc20dc28065754f97
MD5 578e2d9ac0809fc3f13edbf996dcb5b4
BLAKE2b-256 774437aeed50c581c76e1c5bb83b696a06f98f8ecc979ed8564dde3eef908e8b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glfw-2.10.2-py2.py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ffe2b48b51f37b05e8f027f57c0b8cd213affaf22fc83401bd9621692d4c6c8
MD5 71e7419d379417d66ab2d12c8e353abc
BLAKE2b-256 75a49ccee9d5c3b9c5d6bafce3e8d53ab8318eff30124e3c19b95580bebaa6d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for glfw-2.10.2-py2.py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c000b8a5e5fb4374b2c18d12347255ccb92001b9bcf80ef74c56072acbb98fe3
MD5 fca16abfa4e8f1ebdf0a6e01d925872e
BLAKE2b-256 e52e22216db429690aa51fa87d2e2b5e6b610c5a37b9df7768da2927f52f8704

See more details on using hashes here.

File details

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

File metadata

  • Download URL: glfw-2.10.2-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.2-py2.py3-none-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 a04d25bb535a3a29e173ea1abd658e161681b5d3816e00bc51c122f74cd7fa3a
MD5 d1f1a645c71e168f6ad11724812fdce3
BLAKE2b-256 c4805e575ec14f54dc0a644e7215985b9ee7c5044fcc3594d6b83dfdeb04ccd4

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