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 exceptions if no error callback is set (use glfw.ERROR_REPORTING=False to disable this)
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, please follow the steps for Linux below, to build and install GLFW yourself, then place it in one of the library search paths or set PYGLFW_LIBRARY to the location of the library.
Linux
You will need to install the GLFW shared library yourself and should compile 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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for glfw-1.9.0-py2.py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eae0f9a24214db3b71a42f81148e609b6cbdeeff85e3d791f9e78ddf0dad340 |
|
MD5 | 6fd51b0a621628fff572ef0383a61765 |
|
BLAKE2b-256 | 8d76dad08c3fae548aefd96a42e3f8be574c2809219758127f8f62c3fda67d02 |
Hashes for glfw-1.9.0-py2.py3-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4a3ca1898a3e801eb8dc68ddc4376ac46104d0ba65f1542eeb2c9f2a3025b85 |
|
MD5 | 4b67c5377bfcb48fb6d14b372db292bc |
|
BLAKE2b-256 | a2e8cb5b912f48fea515612b60962a031fa3d07487c31fac3cc34ef4d87ee5ec |
Hashes for glfw-1.9.0-py2.py3-none-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9161b0ff617eb121f0a4b85562102559dbb98ff28969f875d82be7c269ace15 |
|
MD5 | d626d06ab9915bb2b2027ad55a99131b |
|
BLAKE2b-256 | 09f3a535d1409a108d18de7060818bbd95e1d5a052124cf02440b5a68bc3cbb9 |
Hashes for glfw-1.9.0-py2.py3-none-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2619e4bd1ed718ced0e85eadeeb555402f05feef097e5bed1f91f3309bf9e95 |
|
MD5 | 3c74566b319b3d0ffe4d74e58c29ab12 |
|
BLAKE2b-256 | af1be1f5d3f945c1039925622e184850806f4aa7ab742833b6fc3d0d87575ee5 |
Hashes for glfw-1.9.0-py2.py3-none-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f811e437b3d550164a6ff39b68b7101b281f4eb09fb04a8e3de7b39fac81536 |
|
MD5 | 06ae685faf380ec40d270057df57a860 |
|
BLAKE2b-256 | 3f8ea643de6f5aa580cfa8e81ec3885dd18ad68528bfe44a0f4b5ce4d198dcfa |