glfw (pyGLFW) is a ctypes-based wrapper for GLFW3, a cross-platform library for OpenGL, OpenGL ES and Vulkan development. It simplifies window creation, context management, and input handling in Python, providing a near one-to-one mapping to the C API with Pythonic naming conventions. The current version is 2.10.0, and it maintains an active release cadence with regular updates.
pip install glfwVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes GLFW, creates a basic window, sets up an OpenGL rendering context, and runs a simple event loop. It clears the window with a solid color until the user closes it. For actual rendering, you would integrate OpenGL (as shown with `OpenGL.GL`) or Vulkan commands within the main loop.
Refactor calls to use `glfw.snake_case_function_name()` and `glfw.CONSTANT_NAME`.
Ensure the native GLFW C library is correctly installed and accessible on your system's library search paths. Environment variables like `PYGLFW_LIBRARY` can be set to point to a specific library path, and `PYGLFW_LIBRARY_VARIANT` (e.g., 'wayland' or 'x11') can be used on Linux to explicitly select the variant.
Upgrade to `glfw>=2.8.0` to ensure proper bundling of GLFW 3.4, or manually install a compatible GLFW 3.4+ C library on version 2.7.0.
Explicitly set the `PYGLFW_LIBRARY` environment variable to the path of the GLFW shared library within your frozen executable's distribution, or ensure the library is placed in a location where `glfw`'s internal search mechanism can find it (e.g., next to the executable).
Install the package using pip: `pip install glfw`
On Windows, ensure the correct Microsoft Visual C++ Redistributable is installed (e.g., VC 2012 for 64-bit Python). On Linux (Debian/Ubuntu), install the development package: `sudo apt-get install libglfw3 libglfw3-dev`. On macOS, ensure GLFW is installed (e.g., via Homebrew) or that the `PYGLFW_LIBRARY` environment variable points to the correct `.dylib` file. For all platforms, ensure the library is in a location where the system can find it (e.g., system PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, or by setting `PYGLFW_LIBRARY`).
Use the Pythonic naming conventions for `pyGLFW` functions. For example, replace `glfwInit()` with `glfw.init()` and `glfwCreateWindow()` with `glfw.create_window()`.
Update your graphics drivers to the latest version. Ensure your system and GPU support the requested OpenGL/Vulkan version. If running in a virtual environment or over remote desktop, ensure that the display server and drivers are configured to allow OpenGL context creation. Try setting GLFW window hints for a different OpenGL version (e.g., `glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3); glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)`).