Debian Codegraph @

README.rst

raw
1 pyGLFW
2 ======
3
4 This module provides Python bindings for `GLFW <http://www.glfw.org/>`__
5 (on GitHub: `glfw/glfw <http://github.com/glfw/glfw>`__). It is a
6 ``ctypes`` wrapper which keeps very close to the original GLFW API,
7 except for:
8
9 - function names use the pythonic ``words_with_underscores`` notation
10 instead of ``camelCase``
11 - ``GLFW_`` and ``glfw`` prefixes have been removed, as their function
12 is replaced by the module namespace
13 (you can use ``from glfw.GLFW import *`` if you prefer the naming
14 convention used by the GLFW C API)
15 - structs have been replaced with Python sequences and namedtuples
16 - functions like ``glfwGetMonitors`` return a list instead of a pointer
17 and an object count
18 - Gamma ramps use floats between 0.0 and 1.0 instead of unsigned shorts
19 (use ``glfw.NORMALIZE_GAMMA_RAMPS=False`` to disable this)
20 - GLFW errors are reported as ``glfw.GLFWError`` warnings if no error
21 callback is set (use ``glfw.ERROR_REPORTING=False`` to disable this,
22 set it to 'warn' instead to issue warnings, set it to 'log' to log it
23 using the 'glfw' logger or set it to a dict to define the behavior for
24 specific error codes)
25 - instead of a sequence for ``GLFWimage`` structs, PIL/pillow ``Image``
26 objects can be used
27
28 Installation
29 ------------
30
31 pyGLFW can be installed using pip:
32
33 .. code:: sh
34
35 pip install glfw
36
37 Windows
38 ~~~~~~~
39
40 The GLFW shared library and Visual C++ runtime are included in the Python wheels.
41
42 To use a different GLFW library, you can set ``PYGLFW_LIBRARY`` to its location.
43
44 macOS
45 ~~~~~
46
47 The GLFW shared library for 64-bit is included in the Python wheels for macOS.
48
49 If you are using a 32-bit Python installation or otherwise cannot use the
50 library downloaded with the wheel, you can build and install it yourself by
51 `compiling GLFW from source <http://www.glfw.org/docs/latest/compile.html>`__
52 (use ``-DBUILD_SHARED_LIBS=ON``).
53
54 pyGLFW will search for the library in a list of search paths (including those
55 in ``DYLD_LIBRARY_PATH``). If you want to use a specific library, you can set
56 the ``PYGLFW_LIBRARY`` environment variable to its path.
57
58 Linux
59 ~~~~~
60
61 The GLFW shared library is included in the Python wheels for Linux. Although
62 pyGLFW will try to detect whether the GLFW library for Wayland or X11 should
63 be used, you can set the ``PYGLFW_LIBRARY_VARIANT`` variable to ``wayland`` or
64 ``x11`` to select either variant of the library.
65
66 If you cannot use these on your system, you can install the GLFW shared
67 library using a package management system (e.g. ``apt install libglfw3``
68 on Debian or Ubuntu) or you can build and install it yourself by
69 `compiling GLFW from source <http://www.glfw.org/docs/latest/compile.html>`__
70 (use ``-DBUILD_SHARED_LIBS=ON``).
71
72 pyGLFW will search for the library in a list of search paths (including those
73 in ``LD_LIBRARY_PATH``). If you want to use a specific library, you can set
74 the ``PYGLFW_LIBRARY`` environment variable to its path.
75
76 cx_Freeze / PyInstaller
77 ~~~~~~~~~~~~~~~~~~~~~~~
78
79 pyGLFW will search for the GLFW library in the current working directory, the directory
80 of the executable and in the package on non-Windows platforms if running in an
81 executable frozen with cx_Freeze or PyInstaller, unless the ``PYGLFW_LIBRARY``
82 environment variable is set.
83
84 Development Version
85 ~~~~~~~~~~~~~~~~~~~
86
87 If you are using the development version of GLFW and would like to use wrappers
88 for currently unreleased macros and functions, you can instead install:
89
90 .. code:: sh
91
92 pip install glfw[preview]
93
94 or set the ``PYGLFW_PREVIEW`` environment variable.
95
96 Note, however, that there will be a slight delay between the development
97 version of GLFW and the wrappers provided by this package.
98
99 Example Code
100 ------------
101
102 The example from the `GLFW
103 documentation <http://www.glfw.org/documentation.html>`__ ported to
104 pyGLFW:
105
106 .. code:: python
107
108 import glfw
109
110 def main():
111 # Initialize the library
112 if not glfw.init():
113 return
114 # Create a windowed mode window and its OpenGL context
115 window = glfw.create_window(640, 480, "Hello World", None, None)
116 if not window:
117 glfw.terminate()
118 return
119
120 # Make the window's context current
121 glfw.make_context_current(window)
122
123 # Loop until the user closes the window
124 while not glfw.window_should_close(window):
125 # Render here, e.g. using pyOpenGL
126
127 # Swap front and back buffers
128 glfw.swap_buffers(window)
129
130 # Poll for and process events
131 glfw.poll_events()
132
133 glfw.terminate()
134
135 if __name__ == "__main__":
136 main()