├── .gitignore
├── .gitlab-ci.yml
├── CHANGELOG.md
├── LICENSE.txt
├── MANIFEST.in
├── README.rst
├── Willy-JL-glfw-3.4.0-patch.diff
├── generate_clike_wrapper.py
├── glfw
├── GLFW.py
├── __init__.py
└── library.py
├── setup.py
├── utils
└── glfw_preview
│ ├── README.md
│ ├── glfw_preview
│ └── __init__.py
│ └── setup.py
└── vcredist
└── msvcr120.dll
/.gitignore:
--------------------------------------------------------------------------------
1 | *.py[cod]
2 | .*
3 | !.gitignore
4 | !.gitlab-ci.yml
5 | *.dll
6 | *.dylib
7 | !vcredist/*.dll
8 |
9 | # Packages
10 | *.egg
11 | *.egg-info
12 | dist
13 | build
14 | eggs
15 | parts
16 | bin
17 | var
18 | sdist
19 | develop-eggs
20 | .installed.cfg
21 | lib
22 | lib64
23 | __pycache__
24 |
25 | # Installer logs
26 | pip-log.txt
27 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | variables:
2 | GLFW_VERSION: "3.4"
3 |
4 | stages:
5 | - build
6 | - package
7 |
8 | build-manylinux_2_28-x86_64:
9 | stage: build
10 | image: quay.io/pypa/manylinux_2_28_x86_64
11 | script:
12 | # Download GLFW from source
13 | - curl -LO https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.zip
14 | - unzip glfw-${GLFW_VERSION}.zip
15 | # Install cmake
16 | - curl -LO https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-Linux-x86_64.tar.gz
17 | - tar xzf cmake-3.28.3-Linux-x86_64.tar.gz
18 | - mv cmake-3.28.3-linux-x86_64 cmake
19 | # Install build dependencies for X11
20 | - yum install -y libXinerama-devel libXrandr-devel libXcursor-devel libXi-devel
21 | # Build GLFW for X11
22 | - mkdir build_x11
23 | - cd build_x11
24 | - ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=ON -DGLFW_BUILD_WAYLAND=OFF
25 | - make
26 | - mkdir -p ../artifacts-manylinux_2_28-x86_64/x11
27 | - cp src/libglfw.so ../artifacts-manylinux_2_28-x86_64/x11/libglfw.so
28 | - cd ..
29 | # Install build dependencies for Wayland
30 | - yum install -y libwayland-client-devel libxkbcommon-devel
31 | - curl -LO https://wayland.freedesktop.org/releases/wayland-protocols-1.17.tar.xz
32 | - tar xf wayland-protocols-1.17.tar.xz
33 | - cd wayland-protocols-1.17
34 | - ./configure
35 | - make install
36 | - cd ..
37 | # Build GLFW for Wayland
38 | - mkdir build_wayland
39 | - cd build_wayland
40 | - PKG_CONFIG_PATH=/usr/local/share/pkgconfig ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=OFF -DGLFW_BUILD_WAYLAND=ON
41 | - make
42 | - mkdir -p ../artifacts-manylinux_2_28-x86_64/wayland
43 | - cp src/libglfw.so ../artifacts-manylinux_2_28-x86_64/wayland/libglfw.so
44 | artifacts:
45 | paths:
46 | - artifacts-manylinux_2_28-x86_64
47 |
48 | build-manylinux_2_28-aarch64:
49 | stage: build
50 | image: quay.io/pypa/manylinux_2_28_aarch64
51 | script:
52 | # Download GLFW from source
53 | - curl -LO https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.zip
54 | - unzip glfw-${GLFW_VERSION}.zip
55 | # Install cmake
56 | - curl -LO https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-linux-aarch64.tar.gz
57 | - tar xzf cmake-3.28.3-linux-aarch64.tar.gz
58 | - mv cmake-3.28.3-linux-aarch64 cmake
59 | # Install build dependencies for X11
60 | - yum install -y libXinerama-devel libXrandr-devel libXcursor-devel libXi-devel
61 | # Build GLFW for X11
62 | - mkdir build_x11
63 | - cd build_x11
64 | - ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=ON -DGLFW_BUILD_WAYLAND=OFF
65 | - make
66 | - mkdir -p ../artifacts-manylinux_2_28-aarch64/x11
67 | - cp src/libglfw.so ../artifacts-manylinux_2_28-aarch64/x11/libglfw.so
68 | - cd ..
69 | # Install build dependencies for Wayland
70 | - yum install -y epel-release
71 | - yum install -y libwayland-client-devel libxkbcommon-devel
72 | - curl -LO https://wayland.freedesktop.org/releases/wayland-protocols-1.17.tar.xz
73 | - tar xf wayland-protocols-1.17.tar.xz
74 | - cd wayland-protocols-1.17
75 | - ./configure
76 | - make install
77 | - cd ..
78 | # Build GLFW for Wayland
79 | - mkdir build_wayland
80 | - cd build_wayland
81 | - PKG_CONFIG_PATH=/usr/local/share/pkgconfig ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=OFF -DGLFW_BUILD_WAYLAND=ON
82 | - make
83 | - mkdir -p ../artifacts-manylinux_2_28-aarch64/wayland
84 | - cp src/libglfw.so ../artifacts-manylinux_2_28-aarch64/wayland/libglfw.so
85 | artifacts:
86 | paths:
87 | - artifacts-manylinux_2_28-aarch64
88 |
89 |
90 | build-manylinux2014-x86_64:
91 | stage: build
92 | image: quay.io/pypa/manylinux2014_x86_64
93 | script:
94 | # Download GLFW from source
95 | - curl -LO https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.zip
96 | - unzip glfw-${GLFW_VERSION}.zip
97 | # Patch GLFW 3.4 to be compatible with manylinux2014
98 | - patch -p0 -i Willy-JL-glfw-3.4.0-patch.diff
99 | # Install cmake
100 | - curl -LO https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-Linux-x86_64.tar.gz
101 | - tar xzf cmake-3.28.3-Linux-x86_64.tar.gz
102 | - mv cmake-3.28.3-linux-x86_64 cmake
103 | # Install build dependencies for X11
104 | - yum install -y libXinerama-devel libXrandr-devel libXcursor-devel libXi-devel
105 | # Build GLFW for X11
106 | - mkdir build_x11
107 | - cd build_x11
108 | - ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=ON -DGLFW_BUILD_WAYLAND=OFF
109 | - make
110 | - mkdir -p ../artifacts-manylinux2014-x86_64/x11
111 | - cp src/libglfw.so ../artifacts-manylinux2014-x86_64/x11/libglfw.so
112 | - cd ..
113 | # Install build dependencies for Wayland
114 | - yum install -y extra-cmake-modules libwayland-client-devel libxkbcommon-devel
115 | - curl -LO https://wayland.freedesktop.org/releases/wayland-protocols-1.17.tar.xz
116 | - tar xf wayland-protocols-1.17.tar.xz
117 | - cd wayland-protocols-1.17
118 | - ./configure
119 | - make install
120 | - cd ..
121 | # Build GLFW for Wayland
122 | - mkdir build_wayland
123 | - cd build_wayland
124 | - PKG_CONFIG_PATH=/usr/local/share/pkgconfig ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=OFF -DGLFW_BUILD_WAYLAND=ON
125 | - make
126 | - mkdir -p ../artifacts-manylinux2014-x86_64/wayland
127 | - cp src/libglfw.so ../artifacts-manylinux2014-x86_64/wayland/libglfw.so
128 | artifacts:
129 | paths:
130 | - artifacts-manylinux2014-x86_64
131 |
132 | build-manylinux2014-aarch64:
133 | stage: build
134 | image: quay.io/pypa/manylinux2014_aarch64
135 | script:
136 | # Download GLFW from source
137 | - curl -LO https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.zip
138 | - unzip glfw-${GLFW_VERSION}.zip
139 | # Patch GLFW 3.4 to be compatible with manylinux2014
140 | - patch -p0 -i Willy-JL-glfw-3.4.0-patch.diff
141 | # Install cmake
142 | - curl -LO https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-linux-aarch64.tar.gz
143 | - tar xzf cmake-3.28.3-linux-aarch64.tar.gz
144 | - mv cmake-3.28.3-linux-aarch64 cmake
145 | # Install build dependencies for X11
146 | - yum install -y libXinerama-devel libXrandr-devel libXcursor-devel libXi-devel
147 | # Build GLFW for X11
148 | - mkdir build_x11
149 | - cd build_x11
150 | - ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=ON -DGLFW_BUILD_WAYLAND=OFF
151 | - make
152 | - mkdir -p ../artifacts-manylinux2014-aarch64/x11
153 | - cp src/libglfw.so ../artifacts-manylinux2014-aarch64/x11/libglfw.so
154 | - cd ..
155 | # Install build dependencies for Wayland
156 | - yum install -y epel-release
157 | - yum install -y extra-cmake-modules libwayland-client-devel libxkbcommon-devel
158 | - curl -LO https://wayland.freedesktop.org/releases/wayland-protocols-1.17.tar.xz
159 | - tar xf wayland-protocols-1.17.tar.xz
160 | - cd wayland-protocols-1.17
161 | - ./configure
162 | - make install
163 | - cd ..
164 | # Build GLFW for Wayland
165 | - mkdir build_wayland
166 | - cd build_wayland
167 | - PKG_CONFIG_PATH=/usr/local/share/pkgconfig ../cmake/bin/cmake ../glfw-${GLFW_VERSION} -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF -DGLFW_BUILD_X11=OFF -DGLFW_BUILD_WAYLAND=ON
168 | - make
169 | - mkdir -p ../artifacts-manylinux2014-aarch64/wayland
170 | - cp src/libglfw.so ../artifacts-manylinux2014-aarch64/wayland/libglfw.so
171 | artifacts:
172 | paths:
173 | - artifacts-manylinux2014-aarch64
174 |
175 | packages:
176 | stage: package
177 | image: ubuntu:latest
178 | script:
179 | - apt-get update -qy
180 | - apt-get install -y curl python3-setuptools python3-wheel unzip
181 | # Build source distribution
182 | - python3 setup.py sdist
183 | # Build wheel for Windows x86
184 | - curl -L -o glfw.bin.zip https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.bin.WIN32.zip
185 | - unzip glfw.bin.zip -d glfw.bin
186 | - cp glfw.bin/*/lib-vc2013/glfw3.dll glfw/glfw3.dll
187 | - cp vcredist/msvcr120.dll glfw/msvcr120.dll
188 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name win32
189 | - rm -rf glfw.bin.zip glfw.bin glfw/glfw3.dll glfw/msvcr120.dll build
190 | # Build wheel for Windows x86_64
191 | - curl -L -o glfw.bin.zip https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.bin.WIN64.zip
192 | - unzip glfw.bin.zip -d glfw.bin
193 | - cp glfw.bin/*/lib-vc2013/glfw3.dll glfw/glfw3.dll
194 | - cp vcredist/msvcr120.dll glfw/msvcr120.dll
195 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name win_amd64
196 | - rm -rf glfw.bin.zip glfw.bin glfw/glfw3.dll glfw/msvcr120.dll build
197 | # Build wheel for macOS x86_64
198 | - curl -L -o glfw.bin.zip https://github.com/glfw/glfw/releases/download/${GLFW_VERSION}/glfw-${GLFW_VERSION}.bin.MACOS.zip
199 | - unzip glfw.bin.zip -d glfw.bin
200 | - cp glfw.bin/*/lib-x86_64/libglfw.3.dylib glfw/libglfw.3.dylib
201 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name macosx_10.6_intel
202 | - rm -rf glfw/libglfw.3.dylib build
203 | # Build wheel for macOS arm64
204 | - cp glfw.bin/*/lib-arm64/libglfw.3.dylib glfw/libglfw.3.dylib
205 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name macosx_11.0_arm64
206 | - rm -rf glfw.bin.zip glfw.bin glfw/libglfw.3.dylib build
207 | # Build wheel for manylinux2014 x86_64
208 | - mkdir -p glfw/x11/
209 | - cp artifacts-manylinux2014-x86_64/x11/libglfw.so glfw/x11/libglfw.so
210 | - mkdir -p glfw/wayland/
211 | - cp artifacts-manylinux2014-x86_64/wayland/libglfw.so glfw/wayland/libglfw.so
212 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name manylinux2014_x86_64
213 | - rm -rf glfw/x11/libglfw.so glfw/wayland/libglfw.so build
214 | # Build wheel for manylinux2014 aarch64
215 | - mkdir -p glfw/x11/
216 | - cp artifacts-manylinux2014-aarch64/x11/libglfw.so glfw/x11/libglfw.so
217 | - mkdir -p glfw/wayland/
218 | - cp artifacts-manylinux2014-aarch64/wayland/libglfw.so glfw/wayland/libglfw.so
219 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name manylinux2014_aarch64
220 | - rm -rf glfw/x11/libglfw.so glfw/wayland/libglfw.so build
221 | # Build wheel for manylinux_2_28 x86_64
222 | - mkdir -p glfw/x11/
223 | - cp artifacts-manylinux_2_28-x86_64/x11/libglfw.so glfw/x11/libglfw.so
224 | - mkdir -p glfw/wayland/
225 | - cp artifacts-manylinux_2_28-x86_64/wayland/libglfw.so glfw/wayland/libglfw.so
226 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name manylinux_2_28_x86_64
227 | - rm -rf glfw/x11/libglfw.so glfw/wayland/libglfw.so build
228 | # Build wheel for manylinux_2_28 aarch64
229 | - mkdir -p glfw/x11/
230 | - cp artifacts-manylinux_2_28-aarch64/x11/libglfw.so glfw/x11/libglfw.so
231 | - mkdir -p glfw/wayland/
232 | - cp artifacts-manylinux_2_28-aarch64/wayland/libglfw.so glfw/wayland/libglfw.so
233 | - python3 setup.py bdist_wheel --python-tag py2.py27.py3.py30.py31.py32.py33.py34.py35.py36.py37.py38.p39.p310.p311.p312.p313 --plat-name manylinux_2_28_aarch64
234 | - rm -rf glfw/x11/libglfw.so glfw/wayland/libglfw.so build
235 | # Build source distribution for glfw_preview helper package
236 | - cd utils/glfw_preview
237 | - python3 setup.py sdist
238 | - cp dist/* ../../dist
239 | - cd ../..
240 | artifacts:
241 | paths:
242 | - dist/
243 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | For information on changes in GLFW itself, see the [GLFW version history](https://www.glfw.org/changelog.html).
6 |
7 | ## [2.9.0] - 2025-04-15
8 | - Added library search paths for various architectures
9 |
10 | ## [2.8.0] - 2024-11-22
11 | - Update to GLFW 3.4
12 |
13 | ## [2.7.0] - 2024-02-24
14 | - Included GLFW 3.4 functions and definitions without preview
15 |
16 | ## [2.6.5] - 2024-01-24
17 | - Fixed Python version check
18 |
19 | ## [2.6.4] - 2023-12-16
20 | - Updated to GLFW 3.3.9
21 |
22 | ## [2.6.3] - 2023-11-17
23 | - Fixed wrapper for glfwGetMonitorWorkarea
24 |
25 | ## [2.6.2] - 2023-06-30
26 | - Implemented search for GLFW library specific to frozen executables
27 |
28 | ## [2.6.1] - 2023-06-23
29 | - Revert changes made in 2.6.0
30 | - Do not search for GLFW library when running in a frozen executable
31 |
32 | ## [2.6.0] - 2023-06-23
33 | - Use multiprocessing for library version detection on non-Windows systems
34 |
35 | ## [2.5.9] - 2023-04-01
36 | - Fixed package version in CHANGELOG.md and glfw/__init__.py
37 |
38 | ## [2.5.8] - 2023-04-01
39 | - Added more wrappers for unreleased macros
40 |
41 | ## [2.5.7] - 2023-03-15
42 | - Added support for PYGLFW_LIBRARY_VARIANT
43 |
44 | ## [2.5.6] - 2023-02-01
45 | - Added warnings for deprecated functions
46 |
47 | ## [2.5.5] - 2022-09-07
48 | - Added wrappers for unreleased macros
49 | - Fixed set_monitor_user_pointer and get_monitor_user_pointer
50 |
51 | ## [2.5.4] - 2022-07-23
52 | - Updated to GLFW 3.3.8
53 |
54 | ## [2.5.3] - 2022-04-09
55 | - Updated to GLFW 3.3.7
56 |
57 | ## [2.5.2] - 2022-04-01
58 | - Fixed swapped HAT_DOWN and HAT_RIGHT constants
59 |
60 | ## [2.5.1] - 2022-02-27
61 | - Updated to GLFW 3.3.6
62 |
63 | ## [2.5.0] - 2021-12-18
64 | - Added /usr/lib/arm-linux-gnueabihf to library search paths
65 |
66 | ## [2.4.0] - 2021-11-07
67 | - Added macOS wheels for arm64
68 | - Added wrappers for unreleased macros and functions
69 | - Updated to GLFW 3.3.5
70 |
71 | ## [2.3.0] - 2021-10-01
72 | - Added /opt/homebrew/lib to library search paths
73 |
74 | ## [2.2.0] - 2021-09-09
75 | - Added Linux wheels for aarch64
76 | - Updated to GLFW 3.3.4
77 |
78 | ## [2.1.0] - 2021-02-28
79 | - Updated to GLFW 3.3.3
80 |
81 | ## [2.0.0] - 2020-10-04
82 | - Changed default error reporting method to warn
83 | - Allow dict for ERROR_REPORTING
84 |
85 | ## [1.12.0] - 2020-07-10
86 | - Added support for CFFI pointers for Vulkan objects
87 |
88 | ## [1.11.2] - 2020-06-03
89 | - Fixed missing parameter in set_window_opacity
90 | - Replaced non-ASCII whitespace
91 |
92 | ## [1.11.1] - 2020-05-15
93 | - Fixed a TypeError in _GLFWgamepadstate
94 |
95 | ## [1.11.0] - 2020-02-21
96 | - Updated to GLFW 3.3.2
97 | - Include support for both X11 and Wayland libraries in the wheel
98 |
99 | ## [1.10.1] - 2020-01-21
100 | - Fixed default error callback name
101 |
102 | ## [1.10.0] - 2020-01-19
103 | - Added more options to error reporting
104 |
105 | ## [1.9.1] - 2020-01-08
106 | - Added conda search path for Windows
107 |
108 | ## [1.9.0] - 2019-12-30
109 | - Added wrappers for native functions
110 |
111 | ## [1.8.7] - 2019-12-10
112 | - Fixed glfwGetMonitorContentScale
113 |
114 | ## [1.8.6] - 2019-12-09
115 | - Added macOS wheels
116 | - Added Microsoft Visual C++ runtime libraries to Windows wheels
117 |
118 | ## [1.8.5] - 2019-11-28
119 | - Added /usr/lib/aarch64-linux-gnu/ to library search paths
120 |
121 | ## [1.8.4] - 2019-11-04
122 | - Fix pointer types in get_window_content_scale
123 |
124 | ## [1.8.3] - 2019-08-22
125 | - Updated the GLFW version in the wheels to 3.3
126 |
127 | ## [1.8.2] - 2019-07-06
128 | - Added the sys.prefix/lib to the search path
129 |
130 | ## [1.8.1] - 2019-05-21
131 | - Added the changelog back to the source distribution
132 |
133 | ## [1.8.0] - 2019-05-11
134 | - Update for GLFW 3.3
135 | - Fixed typo `set_get_window_frame_size`
136 |
137 | ## [1.7.1] - 2019-02-02
138 | - Fixed exception re-raising for Python 2
139 |
140 | ## [1.7.0] - 2018-07-09
141 | - Added glfw.GLFW for the naming convention used by the GLFW C API
142 |
143 | ## [1.6.0] - 2018-03-30
144 | - Added NORMALIZE_GAMMA_RAMPS
145 | - Use namedtuples for structs
146 | - Moved library loading to glfw.library
147 |
148 | ## [1.5.1] - 2018-01-24
149 | - Improved packaging
150 |
151 | ## [1.5.0] - 2018-01-09
152 | - Fixed a bug in set_window_icon
153 | - Added support for PIL/pillow Image objects
154 |
155 | ## [1.4.0] - 2017-02-22
156 | - Improved library search paths
157 |
158 | ## [1.3.0] - 2016-07-28
159 | - Improved error and exception handling
160 |
161 | ## [1.2.0] - 2016-06-17
162 | - Update for GLFW 3.2
163 |
164 | ## [1.0.0] - 2014-03-23
165 | - Initial release.
166 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013-2019 Florian Rhiem
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include README.rst
2 | include CHANGELOG.md
3 | include LICENSE.txt
4 |
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | pyGLFW
2 | ======
3 |
4 | This module provides Python bindings for `GLFW `__
5 | (on GitHub: `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 `__
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 `__
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 `__ 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()
137 |
--------------------------------------------------------------------------------
/Willy-JL-glfw-3.4.0-patch.diff:
--------------------------------------------------------------------------------
1 | diff -ur glfw-3.4/examples/particles.c glfw-3.4-fork/examples/particles.c
2 | --- glfw-3.4/examples/particles.c 2024-11-22 13:22:48
3 | +++ glfw-3.4-fork/examples/particles.c 2024-11-22 13:22:29
4 | @@ -24,6 +24,8 @@
5 | //
6 | //========================================================================
7 |
8 | +#define _GNU_SOURCE
9 | +
10 | #if defined(_MSC_VER)
11 | // Make MS math.h define M_PI
12 | #define _USE_MATH_DEFINES
13 | diff -ur glfw-3.4/src/linux_joystick.c glfw-3.4-fork/src/linux_joystick.c
14 | --- glfw-3.4/src/linux_joystick.c 2024-11-22 13:22:48
15 | +++ glfw-3.4-fork/src/linux_joystick.c 2024-11-22 13:22:29
16 | @@ -25,6 +25,8 @@
17 | //
18 | //========================================================================
19 |
20 | +#define _GNU_SOURCE
21 | +
22 | #include "internal.h"
23 |
24 | #if defined(GLFW_BUILD_LINUX_JOYSTICK)
25 | diff -ur glfw-3.4/src/posix_time.c glfw-3.4-fork/src/posix_time.c
26 | --- glfw-3.4/src/posix_time.c 2024-11-22 13:22:48
27 | +++ glfw-3.4-fork/src/posix_time.c 2024-11-22 13:22:29
28 | @@ -25,6 +25,8 @@
29 | //
30 | //========================================================================
31 |
32 | +#define _GNU_SOURCE
33 | +
34 | #include "internal.h"
35 |
36 | #if defined(GLFW_BUILD_POSIX_TIMER)
37 | diff -ur glfw-3.4/src/wl_init.c glfw-3.4-fork/src/wl_init.c
38 | --- glfw-3.4/src/wl_init.c 2024-11-22 13:22:48
39 | +++ glfw-3.4-fork/src/wl_init.c 2024-11-22 13:22:29
40 | @@ -24,6 +24,8 @@
41 | //
42 | //========================================================================
43 |
44 | +#define _GNU_SOURCE
45 | +
46 | #include "internal.h"
47 |
48 | #if defined(_GLFW_WAYLAND)
49 | diff -ur glfw-3.4/src/wl_window.c glfw-3.4-fork/src/wl_window.c
50 | --- glfw-3.4/src/wl_window.c 2024-11-22 13:22:48
51 | +++ glfw-3.4-fork/src/wl_window.c 2024-11-22 13:22:29
52 | @@ -40,7 +40,9 @@
53 | #include
54 | #include
55 | #include
56 | +#if __has_include()
57 | #include
58 | +#endif
59 |
60 | #include "wayland-client-protocol.h"
61 | #include "xdg-shell-client-protocol.h"
62 |
--------------------------------------------------------------------------------
/generate_clike_wrapper.py:
--------------------------------------------------------------------------------
1 | """
2 | This file imports glfw and converts constant and function names to the style
3 | of the GLFW C API, adding GLFW_ and glfw prefixes and using CamelCase for
4 | function names.
5 |
6 | This file is only needed to be run when adding functions to the wrapper.
7 | """
8 |
9 | from collections import OrderedDict
10 | import glfw
11 |
12 | constant_names = OrderedDict()
13 | function_names = OrderedDict()
14 | constant_type = int
15 | function_type = type(glfw.init)
16 | for pythonic_name in sorted(dir(glfw)):
17 | if pythonic_name.startswith('_'):
18 | continue
19 | obj = getattr(glfw, pythonic_name)
20 | if isinstance(obj, function_type):
21 | if pythonic_name == 'get_joystick_guid':
22 | cstyle_name = 'glfwGetJoystickGUID'
23 | else:
24 | cstyle_name = 'glfw' + ''.join(word.title() for word in pythonic_name.split('_'))
25 | function_names[pythonic_name] = cstyle_name
26 | elif isinstance(obj, constant_type):
27 | cstyle_name = 'GLFW_' + pythonic_name
28 | constant_names[pythonic_name] = cstyle_name
29 | print('""" Automatically generated C-style module for pyGLFW """')
30 | print('from . import (')
31 | for pythonic_name, cstyle_name in constant_names.items():
32 | print(' {} as {},'.format(pythonic_name, cstyle_name))
33 | for pythonic_name, cstyle_name in function_names.items():
34 | print(' {} as {},'.format(pythonic_name, cstyle_name))
35 | print(')')
36 |
--------------------------------------------------------------------------------
/glfw/GLFW.py:
--------------------------------------------------------------------------------
1 | """ Automatically generated C-style module for pyGLFW """
2 | from . import (
3 | _glfw,
4 | ACCUM_ALPHA_BITS as GLFW_ACCUM_ALPHA_BITS,
5 | ACCUM_BLUE_BITS as GLFW_ACCUM_BLUE_BITS,
6 | ACCUM_GREEN_BITS as GLFW_ACCUM_GREEN_BITS,
7 | ACCUM_RED_BITS as GLFW_ACCUM_RED_BITS,
8 | ALPHA_BITS as GLFW_ALPHA_BITS,
9 | ANGLE_PLATFORM_TYPE as GLFW_ANGLE_PLATFORM_TYPE,
10 | ANGLE_PLATFORM_TYPE_D3D11 as GLFW_ANGLE_PLATFORM_TYPE_D3D11,
11 | ANGLE_PLATFORM_TYPE_D3D9 as GLFW_ANGLE_PLATFORM_TYPE_D3D9,
12 | ANGLE_PLATFORM_TYPE_METAL as GLFW_ANGLE_PLATFORM_TYPE_METAL,
13 | ANGLE_PLATFORM_TYPE_NONE as GLFW_ANGLE_PLATFORM_TYPE_NONE,
14 | ANGLE_PLATFORM_TYPE_OPENGL as GLFW_ANGLE_PLATFORM_TYPE_OPENGL,
15 | ANGLE_PLATFORM_TYPE_OPENGLES as GLFW_ANGLE_PLATFORM_TYPE_OPENGLES,
16 | ANGLE_PLATFORM_TYPE_VULKAN as GLFW_ANGLE_PLATFORM_TYPE_VULKAN,
17 | ANY_PLATFORM as GLFW_ANY_PLATFORM,
18 | ANY_POSITION as GLFW_ANY_POSITION,
19 | ANY_RELEASE_BEHAVIOR as GLFW_ANY_RELEASE_BEHAVIOR,
20 | API_UNAVAILABLE as GLFW_API_UNAVAILABLE,
21 | ARROW_CURSOR as GLFW_ARROW_CURSOR,
22 | AUTO_ICONIFY as GLFW_AUTO_ICONIFY,
23 | AUX_BUFFERS as GLFW_AUX_BUFFERS,
24 | BLUE_BITS as GLFW_BLUE_BITS,
25 | CENTER_CURSOR as GLFW_CENTER_CURSOR,
26 | CLIENT_API as GLFW_CLIENT_API,
27 | COCOA_CHDIR_RESOURCES as GLFW_COCOA_CHDIR_RESOURCES,
28 | COCOA_FRAME_NAME as GLFW_COCOA_FRAME_NAME,
29 | COCOA_GRAPHICS_SWITCHING as GLFW_COCOA_GRAPHICS_SWITCHING,
30 | COCOA_MENUBAR as GLFW_COCOA_MENUBAR,
31 | COCOA_RETINA_FRAMEBUFFER as GLFW_COCOA_RETINA_FRAMEBUFFER,
32 | CONNECTED as GLFW_CONNECTED,
33 | CONTEXT_CREATION_API as GLFW_CONTEXT_CREATION_API,
34 | CONTEXT_DEBUG as GLFW_CONTEXT_DEBUG,
35 | CONTEXT_NO_ERROR as GLFW_CONTEXT_NO_ERROR,
36 | CONTEXT_RELEASE_BEHAVIOR as GLFW_CONTEXT_RELEASE_BEHAVIOR,
37 | CONTEXT_REVISION as GLFW_CONTEXT_REVISION,
38 | CONTEXT_ROBUSTNESS as GLFW_CONTEXT_ROBUSTNESS,
39 | CONTEXT_VERSION_MAJOR as GLFW_CONTEXT_VERSION_MAJOR,
40 | CONTEXT_VERSION_MINOR as GLFW_CONTEXT_VERSION_MINOR,
41 | CROSSHAIR_CURSOR as GLFW_CROSSHAIR_CURSOR,
42 | CURSOR as GLFW_CURSOR,
43 | CURSOR_CAPTURED as GLFW_CURSOR_CAPTURED,
44 | CURSOR_DISABLED as GLFW_CURSOR_DISABLED,
45 | CURSOR_HIDDEN as GLFW_CURSOR_HIDDEN,
46 | CURSOR_NORMAL as GLFW_CURSOR_NORMAL,
47 | CURSOR_UNAVAILABLE as GLFW_CURSOR_UNAVAILABLE,
48 | DECORATED as GLFW_DECORATED,
49 | DEPTH_BITS as GLFW_DEPTH_BITS,
50 | DISCONNECTED as GLFW_DISCONNECTED,
51 | DONT_CARE as GLFW_DONT_CARE,
52 | DOUBLEBUFFER as GLFW_DOUBLEBUFFER,
53 | EGL_CONTEXT_API as GLFW_EGL_CONTEXT_API,
54 | ERROR_REPORTING as GLFW_ERROR_REPORTING,
55 | FALSE as GLFW_FALSE,
56 | FEATURE_UNAVAILABLE as GLFW_FEATURE_UNAVAILABLE,
57 | FEATURE_UNIMPLEMENTED as GLFW_FEATURE_UNIMPLEMENTED,
58 | FLOATING as GLFW_FLOATING,
59 | FOCUSED as GLFW_FOCUSED,
60 | FOCUS_ON_SHOW as GLFW_FOCUS_ON_SHOW,
61 | FORMAT_UNAVAILABLE as GLFW_FORMAT_UNAVAILABLE,
62 | GAMEPAD_AXIS_LAST as GLFW_GAMEPAD_AXIS_LAST,
63 | GAMEPAD_AXIS_LEFT_TRIGGER as GLFW_GAMEPAD_AXIS_LEFT_TRIGGER,
64 | GAMEPAD_AXIS_LEFT_X as GLFW_GAMEPAD_AXIS_LEFT_X,
65 | GAMEPAD_AXIS_LEFT_Y as GLFW_GAMEPAD_AXIS_LEFT_Y,
66 | GAMEPAD_AXIS_RIGHT_TRIGGER as GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER,
67 | GAMEPAD_AXIS_RIGHT_X as GLFW_GAMEPAD_AXIS_RIGHT_X,
68 | GAMEPAD_AXIS_RIGHT_Y as GLFW_GAMEPAD_AXIS_RIGHT_Y,
69 | GAMEPAD_BUTTON_A as GLFW_GAMEPAD_BUTTON_A,
70 | GAMEPAD_BUTTON_B as GLFW_GAMEPAD_BUTTON_B,
71 | GAMEPAD_BUTTON_BACK as GLFW_GAMEPAD_BUTTON_BACK,
72 | GAMEPAD_BUTTON_CIRCLE as GLFW_GAMEPAD_BUTTON_CIRCLE,
73 | GAMEPAD_BUTTON_CROSS as GLFW_GAMEPAD_BUTTON_CROSS,
74 | GAMEPAD_BUTTON_DPAD_DOWN as GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
75 | GAMEPAD_BUTTON_DPAD_LEFT as GLFW_GAMEPAD_BUTTON_DPAD_LEFT,
76 | GAMEPAD_BUTTON_DPAD_RIGHT as GLFW_GAMEPAD_BUTTON_DPAD_RIGHT,
77 | GAMEPAD_BUTTON_DPAD_UP as GLFW_GAMEPAD_BUTTON_DPAD_UP,
78 | GAMEPAD_BUTTON_GUIDE as GLFW_GAMEPAD_BUTTON_GUIDE,
79 | GAMEPAD_BUTTON_LAST as GLFW_GAMEPAD_BUTTON_LAST,
80 | GAMEPAD_BUTTON_LEFT_BUMPER as GLFW_GAMEPAD_BUTTON_LEFT_BUMPER,
81 | GAMEPAD_BUTTON_LEFT_THUMB as GLFW_GAMEPAD_BUTTON_LEFT_THUMB,
82 | GAMEPAD_BUTTON_RIGHT_BUMPER as GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER,
83 | GAMEPAD_BUTTON_RIGHT_THUMB as GLFW_GAMEPAD_BUTTON_RIGHT_THUMB,
84 | GAMEPAD_BUTTON_SQUARE as GLFW_GAMEPAD_BUTTON_SQUARE,
85 | GAMEPAD_BUTTON_START as GLFW_GAMEPAD_BUTTON_START,
86 | GAMEPAD_BUTTON_TRIANGLE as GLFW_GAMEPAD_BUTTON_TRIANGLE,
87 | GAMEPAD_BUTTON_X as GLFW_GAMEPAD_BUTTON_X,
88 | GAMEPAD_BUTTON_Y as GLFW_GAMEPAD_BUTTON_Y,
89 | GREEN_BITS as GLFW_GREEN_BITS,
90 | HAND_CURSOR as GLFW_HAND_CURSOR,
91 | HAT_CENTERED as GLFW_HAT_CENTERED,
92 | HAT_DOWN as GLFW_HAT_DOWN,
93 | HAT_LEFT as GLFW_HAT_LEFT,
94 | HAT_LEFT_DOWN as GLFW_HAT_LEFT_DOWN,
95 | HAT_LEFT_UP as GLFW_HAT_LEFT_UP,
96 | HAT_RIGHT as GLFW_HAT_RIGHT,
97 | HAT_RIGHT_DOWN as GLFW_HAT_RIGHT_DOWN,
98 | HAT_RIGHT_UP as GLFW_HAT_RIGHT_UP,
99 | HAT_UP as GLFW_HAT_UP,
100 | HOVERED as GLFW_HOVERED,
101 | HRESIZE_CURSOR as GLFW_HRESIZE_CURSOR,
102 | IBEAM_CURSOR as GLFW_IBEAM_CURSOR,
103 | ICONIFIED as GLFW_ICONIFIED,
104 | INVALID_ENUM as GLFW_INVALID_ENUM,
105 | INVALID_VALUE as GLFW_INVALID_VALUE,
106 | JOYSTICK_1 as GLFW_JOYSTICK_1,
107 | JOYSTICK_10 as GLFW_JOYSTICK_10,
108 | JOYSTICK_11 as GLFW_JOYSTICK_11,
109 | JOYSTICK_12 as GLFW_JOYSTICK_12,
110 | JOYSTICK_13 as GLFW_JOYSTICK_13,
111 | JOYSTICK_14 as GLFW_JOYSTICK_14,
112 | JOYSTICK_15 as GLFW_JOYSTICK_15,
113 | JOYSTICK_16 as GLFW_JOYSTICK_16,
114 | JOYSTICK_2 as GLFW_JOYSTICK_2,
115 | JOYSTICK_3 as GLFW_JOYSTICK_3,
116 | JOYSTICK_4 as GLFW_JOYSTICK_4,
117 | JOYSTICK_5 as GLFW_JOYSTICK_5,
118 | JOYSTICK_6 as GLFW_JOYSTICK_6,
119 | JOYSTICK_7 as GLFW_JOYSTICK_7,
120 | JOYSTICK_8 as GLFW_JOYSTICK_8,
121 | JOYSTICK_9 as GLFW_JOYSTICK_9,
122 | JOYSTICK_HAT_BUTTONS as GLFW_JOYSTICK_HAT_BUTTONS,
123 | JOYSTICK_LAST as GLFW_JOYSTICK_LAST,
124 | KEY_0 as GLFW_KEY_0,
125 | KEY_1 as GLFW_KEY_1,
126 | KEY_2 as GLFW_KEY_2,
127 | KEY_3 as GLFW_KEY_3,
128 | KEY_4 as GLFW_KEY_4,
129 | KEY_5 as GLFW_KEY_5,
130 | KEY_6 as GLFW_KEY_6,
131 | KEY_7 as GLFW_KEY_7,
132 | KEY_8 as GLFW_KEY_8,
133 | KEY_9 as GLFW_KEY_9,
134 | KEY_A as GLFW_KEY_A,
135 | KEY_APOSTROPHE as GLFW_KEY_APOSTROPHE,
136 | KEY_B as GLFW_KEY_B,
137 | KEY_BACKSLASH as GLFW_KEY_BACKSLASH,
138 | KEY_BACKSPACE as GLFW_KEY_BACKSPACE,
139 | KEY_C as GLFW_KEY_C,
140 | KEY_CAPS_LOCK as GLFW_KEY_CAPS_LOCK,
141 | KEY_COMMA as GLFW_KEY_COMMA,
142 | KEY_D as GLFW_KEY_D,
143 | KEY_DELETE as GLFW_KEY_DELETE,
144 | KEY_DOWN as GLFW_KEY_DOWN,
145 | KEY_E as GLFW_KEY_E,
146 | KEY_END as GLFW_KEY_END,
147 | KEY_ENTER as GLFW_KEY_ENTER,
148 | KEY_EQUAL as GLFW_KEY_EQUAL,
149 | KEY_ESCAPE as GLFW_KEY_ESCAPE,
150 | KEY_F as GLFW_KEY_F,
151 | KEY_F1 as GLFW_KEY_F1,
152 | KEY_F10 as GLFW_KEY_F10,
153 | KEY_F11 as GLFW_KEY_F11,
154 | KEY_F12 as GLFW_KEY_F12,
155 | KEY_F13 as GLFW_KEY_F13,
156 | KEY_F14 as GLFW_KEY_F14,
157 | KEY_F15 as GLFW_KEY_F15,
158 | KEY_F16 as GLFW_KEY_F16,
159 | KEY_F17 as GLFW_KEY_F17,
160 | KEY_F18 as GLFW_KEY_F18,
161 | KEY_F19 as GLFW_KEY_F19,
162 | KEY_F2 as GLFW_KEY_F2,
163 | KEY_F20 as GLFW_KEY_F20,
164 | KEY_F21 as GLFW_KEY_F21,
165 | KEY_F22 as GLFW_KEY_F22,
166 | KEY_F23 as GLFW_KEY_F23,
167 | KEY_F24 as GLFW_KEY_F24,
168 | KEY_F25 as GLFW_KEY_F25,
169 | KEY_F3 as GLFW_KEY_F3,
170 | KEY_F4 as GLFW_KEY_F4,
171 | KEY_F5 as GLFW_KEY_F5,
172 | KEY_F6 as GLFW_KEY_F6,
173 | KEY_F7 as GLFW_KEY_F7,
174 | KEY_F8 as GLFW_KEY_F8,
175 | KEY_F9 as GLFW_KEY_F9,
176 | KEY_G as GLFW_KEY_G,
177 | KEY_GRAVE_ACCENT as GLFW_KEY_GRAVE_ACCENT,
178 | KEY_H as GLFW_KEY_H,
179 | KEY_HOME as GLFW_KEY_HOME,
180 | KEY_I as GLFW_KEY_I,
181 | KEY_INSERT as GLFW_KEY_INSERT,
182 | KEY_J as GLFW_KEY_J,
183 | KEY_K as GLFW_KEY_K,
184 | KEY_KP_0 as GLFW_KEY_KP_0,
185 | KEY_KP_1 as GLFW_KEY_KP_1,
186 | KEY_KP_2 as GLFW_KEY_KP_2,
187 | KEY_KP_3 as GLFW_KEY_KP_3,
188 | KEY_KP_4 as GLFW_KEY_KP_4,
189 | KEY_KP_5 as GLFW_KEY_KP_5,
190 | KEY_KP_6 as GLFW_KEY_KP_6,
191 | KEY_KP_7 as GLFW_KEY_KP_7,
192 | KEY_KP_8 as GLFW_KEY_KP_8,
193 | KEY_KP_9 as GLFW_KEY_KP_9,
194 | KEY_KP_ADD as GLFW_KEY_KP_ADD,
195 | KEY_KP_DECIMAL as GLFW_KEY_KP_DECIMAL,
196 | KEY_KP_DIVIDE as GLFW_KEY_KP_DIVIDE,
197 | KEY_KP_ENTER as GLFW_KEY_KP_ENTER,
198 | KEY_KP_EQUAL as GLFW_KEY_KP_EQUAL,
199 | KEY_KP_MULTIPLY as GLFW_KEY_KP_MULTIPLY,
200 | KEY_KP_SUBTRACT as GLFW_KEY_KP_SUBTRACT,
201 | KEY_L as GLFW_KEY_L,
202 | KEY_LAST as GLFW_KEY_LAST,
203 | KEY_LEFT as GLFW_KEY_LEFT,
204 | KEY_LEFT_ALT as GLFW_KEY_LEFT_ALT,
205 | KEY_LEFT_BRACKET as GLFW_KEY_LEFT_BRACKET,
206 | KEY_LEFT_CONTROL as GLFW_KEY_LEFT_CONTROL,
207 | KEY_LEFT_SHIFT as GLFW_KEY_LEFT_SHIFT,
208 | KEY_LEFT_SUPER as GLFW_KEY_LEFT_SUPER,
209 | KEY_M as GLFW_KEY_M,
210 | KEY_MENU as GLFW_KEY_MENU,
211 | KEY_MINUS as GLFW_KEY_MINUS,
212 | KEY_N as GLFW_KEY_N,
213 | KEY_NUM_LOCK as GLFW_KEY_NUM_LOCK,
214 | KEY_O as GLFW_KEY_O,
215 | KEY_P as GLFW_KEY_P,
216 | KEY_PAGE_DOWN as GLFW_KEY_PAGE_DOWN,
217 | KEY_PAGE_UP as GLFW_KEY_PAGE_UP,
218 | KEY_PAUSE as GLFW_KEY_PAUSE,
219 | KEY_PERIOD as GLFW_KEY_PERIOD,
220 | KEY_PRINT_SCREEN as GLFW_KEY_PRINT_SCREEN,
221 | KEY_Q as GLFW_KEY_Q,
222 | KEY_R as GLFW_KEY_R,
223 | KEY_RIGHT as GLFW_KEY_RIGHT,
224 | KEY_RIGHT_ALT as GLFW_KEY_RIGHT_ALT,
225 | KEY_RIGHT_BRACKET as GLFW_KEY_RIGHT_BRACKET,
226 | KEY_RIGHT_CONTROL as GLFW_KEY_RIGHT_CONTROL,
227 | KEY_RIGHT_SHIFT as GLFW_KEY_RIGHT_SHIFT,
228 | KEY_RIGHT_SUPER as GLFW_KEY_RIGHT_SUPER,
229 | KEY_S as GLFW_KEY_S,
230 | KEY_SCROLL_LOCK as GLFW_KEY_SCROLL_LOCK,
231 | KEY_SEMICOLON as GLFW_KEY_SEMICOLON,
232 | KEY_SLASH as GLFW_KEY_SLASH,
233 | KEY_SPACE as GLFW_KEY_SPACE,
234 | KEY_T as GLFW_KEY_T,
235 | KEY_TAB as GLFW_KEY_TAB,
236 | KEY_U as GLFW_KEY_U,
237 | KEY_UNKNOWN as GLFW_KEY_UNKNOWN,
238 | KEY_UP as GLFW_KEY_UP,
239 | KEY_V as GLFW_KEY_V,
240 | KEY_W as GLFW_KEY_W,
241 | KEY_WORLD_1 as GLFW_KEY_WORLD_1,
242 | KEY_WORLD_2 as GLFW_KEY_WORLD_2,
243 | KEY_X as GLFW_KEY_X,
244 | KEY_Y as GLFW_KEY_Y,
245 | KEY_Z as GLFW_KEY_Z,
246 | LOCK_KEY_MODS as GLFW_LOCK_KEY_MODS,
247 | LOSE_CONTEXT_ON_RESET as GLFW_LOSE_CONTEXT_ON_RESET,
248 | MAXIMIZED as GLFW_MAXIMIZED,
249 | MOD_ALT as GLFW_MOD_ALT,
250 | MOD_CAPS_LOCK as GLFW_MOD_CAPS_LOCK,
251 | MOD_CONTROL as GLFW_MOD_CONTROL,
252 | MOD_NUM_LOCK as GLFW_MOD_NUM_LOCK,
253 | MOD_SHIFT as GLFW_MOD_SHIFT,
254 | MOD_SUPER as GLFW_MOD_SUPER,
255 | MOUSE_BUTTON_1 as GLFW_MOUSE_BUTTON_1,
256 | MOUSE_BUTTON_2 as GLFW_MOUSE_BUTTON_2,
257 | MOUSE_BUTTON_3 as GLFW_MOUSE_BUTTON_3,
258 | MOUSE_BUTTON_4 as GLFW_MOUSE_BUTTON_4,
259 | MOUSE_BUTTON_5 as GLFW_MOUSE_BUTTON_5,
260 | MOUSE_BUTTON_6 as GLFW_MOUSE_BUTTON_6,
261 | MOUSE_BUTTON_7 as GLFW_MOUSE_BUTTON_7,
262 | MOUSE_BUTTON_8 as GLFW_MOUSE_BUTTON_8,
263 | MOUSE_BUTTON_LAST as GLFW_MOUSE_BUTTON_LAST,
264 | MOUSE_BUTTON_LEFT as GLFW_MOUSE_BUTTON_LEFT,
265 | MOUSE_BUTTON_MIDDLE as GLFW_MOUSE_BUTTON_MIDDLE,
266 | MOUSE_BUTTON_RIGHT as GLFW_MOUSE_BUTTON_RIGHT,
267 | MOUSE_PASSTHROUGH as GLFW_MOUSE_PASSTHROUGH,
268 | NATIVE_CONTEXT_API as GLFW_NATIVE_CONTEXT_API,
269 | NORMALIZE_GAMMA_RAMPS as GLFW_NORMALIZE_GAMMA_RAMPS,
270 | NOT_ALLOWED_CURSOR as GLFW_NOT_ALLOWED_CURSOR,
271 | NOT_INITIALIZED as GLFW_NOT_INITIALIZED,
272 | NO_API as GLFW_NO_API,
273 | NO_CURRENT_CONTEXT as GLFW_NO_CURRENT_CONTEXT,
274 | NO_ERROR as GLFW_NO_ERROR,
275 | NO_RESET_NOTIFICATION as GLFW_NO_RESET_NOTIFICATION,
276 | NO_ROBUSTNESS as GLFW_NO_ROBUSTNESS,
277 | NO_WINDOW_CONTEXT as GLFW_NO_WINDOW_CONTEXT,
278 | OPENGL_ANY_PROFILE as GLFW_OPENGL_ANY_PROFILE,
279 | OPENGL_API as GLFW_OPENGL_API,
280 | OPENGL_COMPAT_PROFILE as GLFW_OPENGL_COMPAT_PROFILE,
281 | OPENGL_CORE_PROFILE as GLFW_OPENGL_CORE_PROFILE,
282 | OPENGL_DEBUG_CONTEXT as GLFW_OPENGL_DEBUG_CONTEXT,
283 | OPENGL_ES_API as GLFW_OPENGL_ES_API,
284 | OPENGL_FORWARD_COMPAT as GLFW_OPENGL_FORWARD_COMPAT,
285 | OPENGL_PROFILE as GLFW_OPENGL_PROFILE,
286 | OSMESA_CONTEXT_API as GLFW_OSMESA_CONTEXT_API,
287 | OUT_OF_MEMORY as GLFW_OUT_OF_MEMORY,
288 | PLATFORM as GLFW_PLATFORM,
289 | PLATFORM_COCOA as GLFW_PLATFORM_COCOA,
290 | PLATFORM_ERROR as GLFW_PLATFORM_ERROR,
291 | PLATFORM_NULL as GLFW_PLATFORM_NULL,
292 | PLATFORM_UNAVAILABLE as GLFW_PLATFORM_UNAVAILABLE,
293 | PLATFORM_WAYLAND as GLFW_PLATFORM_WAYLAND,
294 | PLATFORM_WIN32 as GLFW_PLATFORM_WIN32,
295 | PLATFORM_X11 as GLFW_PLATFORM_X11,
296 | POINTING_HAND_CURSOR as GLFW_POINTING_HAND_CURSOR,
297 | POSITION_X as GLFW_POSITION_X,
298 | POSITION_Y as GLFW_POSITION_Y,
299 | PRESS as GLFW_PRESS,
300 | RAW_MOUSE_MOTION as GLFW_RAW_MOUSE_MOTION,
301 | RED_BITS as GLFW_RED_BITS,
302 | REFRESH_RATE as GLFW_REFRESH_RATE,
303 | RELEASE as GLFW_RELEASE,
304 | RELEASE_BEHAVIOR_FLUSH as GLFW_RELEASE_BEHAVIOR_FLUSH,
305 | RELEASE_BEHAVIOR_NONE as GLFW_RELEASE_BEHAVIOR_NONE,
306 | REPEAT as GLFW_REPEAT,
307 | RESIZABLE as GLFW_RESIZABLE,
308 | RESIZE_ALL_CURSOR as GLFW_RESIZE_ALL_CURSOR,
309 | RESIZE_EW_CURSOR as GLFW_RESIZE_EW_CURSOR,
310 | RESIZE_NESW_CURSOR as GLFW_RESIZE_NESW_CURSOR,
311 | RESIZE_NS_CURSOR as GLFW_RESIZE_NS_CURSOR,
312 | RESIZE_NWSE_CURSOR as GLFW_RESIZE_NWSE_CURSOR,
313 | SAMPLES as GLFW_SAMPLES,
314 | SCALE_FRAMEBUFFER as GLFW_SCALE_FRAMEBUFFER,
315 | SCALE_TO_MONITOR as GLFW_SCALE_TO_MONITOR,
316 | SRGB_CAPABLE as GLFW_SRGB_CAPABLE,
317 | STENCIL_BITS as GLFW_STENCIL_BITS,
318 | STEREO as GLFW_STEREO,
319 | STICKY_KEYS as GLFW_STICKY_KEYS,
320 | STICKY_MOUSE_BUTTONS as GLFW_STICKY_MOUSE_BUTTONS,
321 | TRANSPARENT_FRAMEBUFFER as GLFW_TRANSPARENT_FRAMEBUFFER,
322 | TRUE as GLFW_TRUE,
323 | VERSION_MAJOR as GLFW_VERSION_MAJOR,
324 | VERSION_MINOR as GLFW_VERSION_MINOR,
325 | VERSION_REVISION as GLFW_VERSION_REVISION,
326 | VERSION_UNAVAILABLE as GLFW_VERSION_UNAVAILABLE,
327 | VISIBLE as GLFW_VISIBLE,
328 | VRESIZE_CURSOR as GLFW_VRESIZE_CURSOR,
329 | WAYLAND_APP_ID as GLFW_WAYLAND_APP_ID,
330 | WAYLAND_DISABLE_LIBDECOR as GLFW_WAYLAND_DISABLE_LIBDECOR,
331 | WAYLAND_LIBDECOR as GLFW_WAYLAND_LIBDECOR,
332 | WAYLAND_PREFER_LIBDECOR as GLFW_WAYLAND_PREFER_LIBDECOR,
333 | WIN32_KEYBOARD_MENU as GLFW_WIN32_KEYBOARD_MENU,
334 | WIN32_SHOWDEFAULT as GLFW_WIN32_SHOWDEFAULT,
335 | X11_CLASS_NAME as GLFW_X11_CLASS_NAME,
336 | X11_INSTANCE_NAME as GLFW_X11_INSTANCE_NAME,
337 | X11_XCB_VULKAN_SURFACE as GLFW_X11_XCB_VULKAN_SURFACE,
338 | create_cursor as glfwCreateCursor,
339 | create_standard_cursor as glfwCreateStandardCursor,
340 | create_window as glfwCreateWindow,
341 | create_window_surface as glfwCreateWindowSurface,
342 | default_window_hints as glfwDefaultWindowHints,
343 | destroy_cursor as glfwDestroyCursor,
344 | destroy_window as glfwDestroyWindow,
345 | extension_supported as glfwExtensionSupported,
346 | focus_window as glfwFocusWindow,
347 | get_clipboard_string as glfwGetClipboardString,
348 | get_current_context as glfwGetCurrentContext,
349 | get_cursor_pos as glfwGetCursorPos,
350 | get_error as glfwGetError,
351 | get_framebuffer_size as glfwGetFramebufferSize,
352 | get_gamepad_name as glfwGetGamepadName,
353 | get_gamepad_state as glfwGetGamepadState,
354 | get_gamma_ramp as glfwGetGammaRamp,
355 | get_input_mode as glfwGetInputMode,
356 | get_instance_proc_address as glfwGetInstanceProcAddress,
357 | get_joystick_axes as glfwGetJoystickAxes,
358 | get_joystick_buttons as glfwGetJoystickButtons,
359 | get_joystick_guid as glfwGetJoystickGUID,
360 | get_joystick_hats as glfwGetJoystickHats,
361 | get_joystick_name as glfwGetJoystickName,
362 | get_joystick_user_pointer as glfwGetJoystickUserPointer,
363 | get_key as glfwGetKey,
364 | get_key_name as glfwGetKeyName,
365 | get_key_scancode as glfwGetKeyScancode,
366 | get_monitor_content_scale as glfwGetMonitorContentScale,
367 | get_monitor_name as glfwGetMonitorName,
368 | get_monitor_physical_size as glfwGetMonitorPhysicalSize,
369 | get_monitor_pos as glfwGetMonitorPos,
370 | get_monitor_user_pointer as glfwGetMonitorUserPointer,
371 | get_monitor_workarea as glfwGetMonitorWorkarea,
372 | get_monitors as glfwGetMonitors,
373 | get_mouse_button as glfwGetMouseButton,
374 | get_physical_device_presentation_support as glfwGetPhysicalDevicePresentationSupport,
375 | get_primary_monitor as glfwGetPrimaryMonitor,
376 | get_proc_address as glfwGetProcAddress,
377 | get_required_instance_extensions as glfwGetRequiredInstanceExtensions,
378 | get_time as glfwGetTime,
379 | get_timer_frequency as glfwGetTimerFrequency,
380 | get_timer_value as glfwGetTimerValue,
381 | get_version as glfwGetVersion,
382 | get_version_string as glfwGetVersionString,
383 | get_video_mode as glfwGetVideoMode,
384 | get_video_modes as glfwGetVideoModes,
385 | get_window_attrib as glfwGetWindowAttrib,
386 | get_window_content_scale as glfwGetWindowContentScale,
387 | get_window_frame_size as glfwGetWindowFrameSize,
388 | get_window_monitor as glfwGetWindowMonitor,
389 | get_window_opacity as glfwGetWindowOpacity,
390 | get_window_pos as glfwGetWindowPos,
391 | get_window_size as glfwGetWindowSize,
392 | get_window_user_pointer as glfwGetWindowUserPointer,
393 | hide_window as glfwHideWindow,
394 | iconify_window as glfwIconifyWindow,
395 | init as glfwInit,
396 | init_hint as glfwInitHint,
397 | joystick_is_gamepad as glfwJoystickIsGamepad,
398 | joystick_present as glfwJoystickPresent,
399 | make_context_current as glfwMakeContextCurrent,
400 | maximize_window as glfwMaximizeWindow,
401 | poll_events as glfwPollEvents,
402 | post_empty_event as glfwPostEmptyEvent,
403 | raw_mouse_motion_supported as glfwRawMouseMotionSupported,
404 | request_window_attention as glfwRequestWindowAttention,
405 | restore_window as glfwRestoreWindow,
406 | set_char_callback as glfwSetCharCallback,
407 | set_char_mods_callback as glfwSetCharModsCallback,
408 | set_clipboard_string as glfwSetClipboardString,
409 | set_cursor as glfwSetCursor,
410 | set_cursor_enter_callback as glfwSetCursorEnterCallback,
411 | set_cursor_pos as glfwSetCursorPos,
412 | set_cursor_pos_callback as glfwSetCursorPosCallback,
413 | set_drop_callback as glfwSetDropCallback,
414 | set_error_callback as glfwSetErrorCallback,
415 | set_framebuffer_size_callback as glfwSetFramebufferSizeCallback,
416 | set_gamma as glfwSetGamma,
417 | set_gamma_ramp as glfwSetGammaRamp,
418 | set_input_mode as glfwSetInputMode,
419 | set_joystick_callback as glfwSetJoystickCallback,
420 | set_joystick_user_pointer as glfwSetJoystickUserPointer,
421 | set_key_callback as glfwSetKeyCallback,
422 | set_monitor_callback as glfwSetMonitorCallback,
423 | set_monitor_user_pointer as glfwSetMonitorUserPointer,
424 | set_mouse_button_callback as glfwSetMouseButtonCallback,
425 | set_scroll_callback as glfwSetScrollCallback,
426 | set_time as glfwSetTime,
427 | set_window_aspect_ratio as glfwSetWindowAspectRatio,
428 | set_window_attrib as glfwSetWindowAttrib,
429 | set_window_close_callback as glfwSetWindowCloseCallback,
430 | set_window_content_scale_callback as glfwSetWindowContentScaleCallback,
431 | set_window_focus_callback as glfwSetWindowFocusCallback,
432 | set_window_icon as glfwSetWindowIcon,
433 | set_window_iconify_callback as glfwSetWindowIconifyCallback,
434 | set_window_maximize_callback as glfwSetWindowMaximizeCallback,
435 | set_window_monitor as glfwSetWindowMonitor,
436 | set_window_opacity as glfwSetWindowOpacity,
437 | set_window_pos as glfwSetWindowPos,
438 | set_window_pos_callback as glfwSetWindowPosCallback,
439 | set_window_refresh_callback as glfwSetWindowRefreshCallback,
440 | set_window_should_close as glfwSetWindowShouldClose,
441 | set_window_size as glfwSetWindowSize,
442 | set_window_size_callback as glfwSetWindowSizeCallback,
443 | set_window_size_limits as glfwSetWindowSizeLimits,
444 | set_window_title as glfwSetWindowTitle,
445 | set_window_user_pointer as glfwSetWindowUserPointer,
446 | show_window as glfwShowWindow,
447 | swap_buffers as glfwSwapBuffers,
448 | swap_interval as glfwSwapInterval,
449 | terminate as glfwTerminate,
450 | update_gamepad_mappings as glfwUpdateGamepadMappings,
451 | vulkan_supported as glfwVulkanSupported,
452 | wait_events as glfwWaitEvents,
453 | wait_events_timeout as glfwWaitEventsTimeout,
454 | window_hint as glfwWindowHint,
455 | window_hint_string as glfwWindowHintString,
456 | window_should_close as glfwWindowShouldClose,
457 | )
458 |
459 | if hasattr(_glfw, 'glfwInitAllocator'):
460 | from . import init_allocator as glfwInitAllocator
461 | if hasattr(_glfw, 'glfwInitVulkanLoader'):
462 | from . import init_vulkan_loader as glfwInitVulkanLoader
463 | if hasattr(_glfw, 'glfwGetPlatform'):
464 | from . import get_platform as glfwGetPlatform
465 | if hasattr(_glfw, 'glfwPlatformSupported'):
466 | from . import platform_supported as glfwPlatformSupported
467 | if hasattr(_glfw, 'glfwGetWindowTitle'):
468 | from . import get_window_title as glfwGetWindowTitle
469 |
470 | from . import _PREVIEW
471 | if _PREVIEW:
472 | from . import (
473 | UNLIMITED_MOUSE_BUTTONS as GLFW_UNLIMITED_MOUSE_BUTTONS
474 | )
475 |
--------------------------------------------------------------------------------
/glfw/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | Python bindings for GLFW.
3 | """
4 |
5 | from __future__ import print_function
6 | from __future__ import division
7 | from __future__ import unicode_literals
8 |
9 | __author__ = 'Florian Rhiem (florian.rhiem@gmail.com)'
10 | __copyright__ = 'Copyright (c) 2013-2024 Florian Rhiem'
11 | __license__ = 'MIT'
12 | __version__ = '2.9.0'
13 |
14 | # By default, GLFW errors will be handled by a pre-defined error callback.
15 | # Depending on the value of ERROR_REPORTING, this callback will:
16 | # - Raise a GLFWError exception, if ERROR_REPORTING is 'raise', 'exception'
17 | # or True.
18 | # - Issue a GLFWError warning, if ERROR_REPORTING is 'warn' or 'warning'.
19 | # - Log on debug level using the 'glfw' logger, if ERROR_REPORTING is 'log'.
20 | # - Ignore the GLFWError, if ERROR_REPORTING is 'ignore' or False.
21 | # If ERROR_REPORTING is a dict containing the specific error code or None as a
22 | # key, the corresponding value will be used.
23 | # Alternatively, you can set a custom error callback using set_error_callback.
24 | ERROR_REPORTING = 'warn'
25 |
26 | # By default (NORMALIZE_GAMMA_RAMPS = True), gamma ramps are expected to
27 | # contain values between 0 and 1, and the conversion to unsigned shorts will
28 | # be performed internally. Set NORMALIZE_GAMMA_RAMPS to False if you want
29 | # to disable this behavior and use integral values between 0 and 65535.
30 | NORMALIZE_GAMMA_RAMPS = True
31 |
32 | import collections
33 | import ctypes
34 | import logging
35 | import os
36 | import functools
37 | import sys
38 | import warnings
39 |
40 | from .library import glfw as _glfw
41 |
42 | if _glfw is None:
43 | raise ImportError("Failed to load GLFW3 shared library.")
44 |
45 | # By default, pyGLFW will only provide functionality from released GLFW
46 | # versions, as using the development version may lead to changing behavior or
47 | # missing functions. If the environment variable PYGLFW_PREVIEW is set or the
48 | # glfw_preview package can be imported, macros and functions from the current
49 | # developtment version of GLFW will be provided. Note that there will still be
50 | # a delay between them getting added to GLFW and being wrapped by pyGLFW, and
51 | # further delay until they are included in a pyGLFW release.
52 | _PREVIEW = os.environ.get('PYGLFW_PREVIEW')
53 | if _PREVIEW is None:
54 | try:
55 | import glfw_preview
56 | _PREVIEW = True
57 | except:
58 | _PREVIEW = False
59 | else:
60 | _PREVIEW = bool(_PREVIEW)
61 |
62 | # Python 3 compatibility:
63 | try:
64 | _getcwd = os.getcwdu
65 | except AttributeError:
66 | _getcwd = os.getcwd
67 | if sys.version_info.major > 2:
68 | _to_char_p = lambda s: s.encode('utf-8')
69 | def _reraise(exception, traceback):
70 | raise exception.with_traceback(traceback)
71 | else:
72 | _to_char_p = lambda s: s
73 | def _reraise(exception, traceback):
74 | # wrapped in exec, as python 3 does not support this variant of raise
75 | exec("raise exception, None, traceback")
76 |
77 | # support for CFFI pointers for Vulkan objects
78 | try:
79 | from cffi import FFI
80 | except ImportError:
81 | _cffi_to_ctypes_void_p = lambda ptr: ptr
82 | else:
83 | ffi = FFI()
84 | def _cffi_to_ctypes_void_p(ptr):
85 | if isinstance(ptr, ffi.CData):
86 | return ctypes.cast(int(ffi.cast('uintptr_t', ptr)), ctypes.c_void_p)
87 | return ptr
88 |
89 |
90 | class GLFWError(UserWarning):
91 | """
92 | Exception class used for reporting GLFW errors.
93 | """
94 | def __init__(self, message, error_code=None):
95 | super(GLFWError, self).__init__(message)
96 | self.error_code = error_code
97 |
98 |
99 | _callback_repositories = []
100 |
101 |
102 | class _GLFWwindow(ctypes.Structure):
103 | """
104 | Wrapper for:
105 | typedef struct GLFWwindow GLFWwindow;
106 | """
107 | _fields_ = [("dummy", ctypes.c_int)]
108 |
109 |
110 | class _GLFWmonitor(ctypes.Structure):
111 | """
112 | Wrapper for:
113 | typedef struct GLFWmonitor GLFWmonitor;
114 | """
115 | _fields_ = [("dummy", ctypes.c_int)]
116 |
117 |
118 | class _GLFWvidmode(ctypes.Structure):
119 | """
120 | Wrapper for:
121 | typedef struct GLFWvidmode GLFWvidmode;
122 | """
123 | _fields_ = [("width", ctypes.c_int),
124 | ("height", ctypes.c_int),
125 | ("red_bits", ctypes.c_int),
126 | ("green_bits", ctypes.c_int),
127 | ("blue_bits", ctypes.c_int),
128 | ("refresh_rate", ctypes.c_uint)]
129 |
130 | GLFWvidmode = collections.namedtuple('GLFWvidmode', [
131 | 'size', 'bits', 'refresh_rate'
132 | ])
133 | Size = collections.namedtuple('Size', [
134 | 'width', 'height'
135 | ])
136 | Bits = collections.namedtuple('Bits', [
137 | 'red', 'green', 'blue'
138 | ])
139 |
140 | def __init__(self):
141 | ctypes.Structure.__init__(self)
142 | self.width = 0
143 | self.height = 0
144 | self.red_bits = 0
145 | self.green_bits = 0
146 | self.blue_bits = 0
147 | self.refresh_rate = 0
148 |
149 | def wrap(self, video_mode):
150 | """
151 | Wraps a nested python sequence.
152 | """
153 | size, bits, self.refresh_rate = video_mode
154 | self.width, self.height = size
155 | self.red_bits, self.green_bits, self.blue_bits = bits
156 |
157 | def unwrap(self):
158 | """
159 | Returns a GLFWvidmode object.
160 | """
161 | size = self.Size(self.width, self.height)
162 | bits = self.Bits(self.red_bits, self.green_bits, self.blue_bits)
163 | return self.GLFWvidmode(size, bits, self.refresh_rate)
164 |
165 |
166 | class _GLFWgammaramp(ctypes.Structure):
167 | """
168 | Wrapper for:
169 | typedef struct GLFWgammaramp GLFWgammaramp;
170 | """
171 | _fields_ = [("red", ctypes.POINTER(ctypes.c_ushort)),
172 | ("green", ctypes.POINTER(ctypes.c_ushort)),
173 | ("blue", ctypes.POINTER(ctypes.c_ushort)),
174 | ("size", ctypes.c_uint)]
175 |
176 | GLFWgammaramp = collections.namedtuple('GLFWgammaramp', [
177 | 'red', 'green', 'blue'
178 | ])
179 |
180 | def __init__(self):
181 | ctypes.Structure.__init__(self)
182 | self.red = None
183 | self.red_array = None
184 | self.green = None
185 | self.green_array = None
186 | self.blue = None
187 | self.blue_array = None
188 | self.size = 0
189 |
190 | def wrap(self, gammaramp):
191 | """
192 | Wraps a nested python sequence.
193 | """
194 | red, green, blue = gammaramp
195 | size = min(len(red), len(green), len(blue))
196 | array_type = ctypes.c_ushort*size
197 | self.size = ctypes.c_uint(size)
198 | self.red_array = array_type()
199 | self.green_array = array_type()
200 | self.blue_array = array_type()
201 | if NORMALIZE_GAMMA_RAMPS:
202 | red = [value * 65535 for value in red]
203 | green = [value * 65535 for value in green]
204 | blue = [value * 65535 for value in blue]
205 | for i in range(self.size):
206 | self.red_array[i] = int(red[i])
207 | self.green_array[i] = int(green[i])
208 | self.blue_array[i] = int(blue[i])
209 | pointer_type = ctypes.POINTER(ctypes.c_ushort)
210 | self.red = ctypes.cast(self.red_array, pointer_type)
211 | self.green = ctypes.cast(self.green_array, pointer_type)
212 | self.blue = ctypes.cast(self.blue_array, pointer_type)
213 |
214 | def unwrap(self):
215 | """
216 | Returns a GLFWgammaramp object.
217 | """
218 | red = [self.red[i] for i in range(self.size)]
219 | green = [self.green[i] for i in range(self.size)]
220 | blue = [self.blue[i] for i in range(self.size)]
221 | if NORMALIZE_GAMMA_RAMPS:
222 | red = [value / 65535.0 for value in red]
223 | green = [value / 65535.0 for value in green]
224 | blue = [value / 65535.0 for value in blue]
225 | return self.GLFWgammaramp(red, green, blue)
226 |
227 |
228 | class _GLFWcursor(ctypes.Structure):
229 | """
230 | Wrapper for:
231 | typedef struct GLFWcursor GLFWcursor;
232 | """
233 | _fields_ = [("dummy", ctypes.c_int)]
234 |
235 |
236 | class _GLFWimage(ctypes.Structure):
237 | """
238 | Wrapper for:
239 | typedef struct GLFWimage GLFWimage;
240 | """
241 | _fields_ = [("width", ctypes.c_int),
242 | ("height", ctypes.c_int),
243 | ("pixels", ctypes.POINTER(ctypes.c_ubyte))]
244 |
245 | GLFWimage = collections.namedtuple('GLFWimage', [
246 | 'width', 'height', 'pixels'
247 | ])
248 |
249 | def __init__(self):
250 | ctypes.Structure.__init__(self)
251 | self.width = 0
252 | self.height = 0
253 | self.pixels = None
254 | self.pixels_array = None
255 |
256 | def wrap(self, image):
257 | """
258 | Wraps a nested python sequence or PIL/pillow Image.
259 | """
260 | if hasattr(image, 'size') and hasattr(image, 'convert'):
261 | # Treat image as PIL/pillow Image object
262 | self.width, self.height = image.size
263 | array_type = ctypes.c_ubyte * 4 * (self.width * self.height)
264 | self.pixels_array = array_type()
265 | pixels = image.convert('RGBA').getdata()
266 | for i, pixel in enumerate(pixels):
267 | self.pixels_array[i] = pixel
268 | else:
269 | self.width, self.height, pixels = image
270 | array_type = ctypes.c_ubyte * 4 * self.width * self.height
271 | self.pixels_array = array_type()
272 | for i in range(self.height):
273 | for j in range(self.width):
274 | for k in range(4):
275 | self.pixels_array[i][j][k] = pixels[i][j][k]
276 | pointer_type = ctypes.POINTER(ctypes.c_ubyte)
277 | self.pixels = ctypes.cast(self.pixels_array, pointer_type)
278 |
279 | def unwrap(self):
280 | """
281 | Returns a GLFWimage object.
282 | """
283 | pixels = [[[int(c) for c in p] for p in l] for l in self.pixels_array]
284 | return self.GLFWimage(self.width, self.height, pixels)
285 |
286 |
287 | class _GLFWgamepadstate(ctypes.Structure):
288 | """
289 | Wrapper for:
290 | typedef struct GLFWgamepadstate GLFWgamepadstate;
291 | """
292 | _fields_ = [("buttons", (ctypes.c_ubyte * 15)),
293 | ("axes", (ctypes.c_float * 6))]
294 |
295 | GLFWgamepadstate = collections.namedtuple('GLFWgamepadstate', [
296 | 'buttons', 'axes'
297 | ])
298 |
299 | def __init__(self):
300 | ctypes.Structure.__init__(self)
301 | self.buttons = (ctypes.c_ubyte * 15)(* [0] * 15)
302 | self.axes = (ctypes.c_float * 6)(* [0] * 6)
303 |
304 | def wrap(self, gamepad_state):
305 | """
306 | Wraps a nested python sequence.
307 | """
308 | buttons, axes = gamepad_state
309 | for i in range(15):
310 | self.buttons[i] = buttons[i]
311 | for i in range(6):
312 | self.axes[i] = axes[i]
313 |
314 | def unwrap(self):
315 | """
316 | Returns a GLFWvidmode object.
317 | """
318 | buttons = [int(button) for button in self.buttons]
319 | axes = [float(axis) for axis in self.axes]
320 | return self.GLFWgamepadstate(buttons, axes)
321 |
322 |
323 | VERSION_MAJOR = 3
324 | VERSION_MINOR = 4
325 | VERSION_REVISION = 0
326 | TRUE = 1
327 | FALSE = 0
328 | RELEASE = 0
329 | PRESS = 1
330 | REPEAT = 2
331 | HAT_CENTERED = 0
332 | HAT_UP = 1
333 | HAT_RIGHT = 2
334 | HAT_DOWN = 4
335 | HAT_LEFT = 8
336 | HAT_RIGHT_UP = HAT_RIGHT | HAT_UP
337 | HAT_RIGHT_DOWN = HAT_RIGHT | HAT_DOWN
338 | HAT_LEFT_UP = HAT_LEFT | HAT_UP
339 | HAT_LEFT_DOWN = HAT_LEFT | HAT_DOWN
340 | KEY_UNKNOWN = -1
341 | KEY_SPACE = 32
342 | KEY_APOSTROPHE = 39
343 | KEY_COMMA = 44
344 | KEY_MINUS = 45
345 | KEY_PERIOD = 46
346 | KEY_SLASH = 47
347 | KEY_0 = 48
348 | KEY_1 = 49
349 | KEY_2 = 50
350 | KEY_3 = 51
351 | KEY_4 = 52
352 | KEY_5 = 53
353 | KEY_6 = 54
354 | KEY_7 = 55
355 | KEY_8 = 56
356 | KEY_9 = 57
357 | KEY_SEMICOLON = 59
358 | KEY_EQUAL = 61
359 | KEY_A = 65
360 | KEY_B = 66
361 | KEY_C = 67
362 | KEY_D = 68
363 | KEY_E = 69
364 | KEY_F = 70
365 | KEY_G = 71
366 | KEY_H = 72
367 | KEY_I = 73
368 | KEY_J = 74
369 | KEY_K = 75
370 | KEY_L = 76
371 | KEY_M = 77
372 | KEY_N = 78
373 | KEY_O = 79
374 | KEY_P = 80
375 | KEY_Q = 81
376 | KEY_R = 82
377 | KEY_S = 83
378 | KEY_T = 84
379 | KEY_U = 85
380 | KEY_V = 86
381 | KEY_W = 87
382 | KEY_X = 88
383 | KEY_Y = 89
384 | KEY_Z = 90
385 | KEY_LEFT_BRACKET = 91
386 | KEY_BACKSLASH = 92
387 | KEY_RIGHT_BRACKET = 93
388 | KEY_GRAVE_ACCENT = 96
389 | KEY_WORLD_1 = 161
390 | KEY_WORLD_2 = 162
391 | KEY_ESCAPE = 256
392 | KEY_ENTER = 257
393 | KEY_TAB = 258
394 | KEY_BACKSPACE = 259
395 | KEY_INSERT = 260
396 | KEY_DELETE = 261
397 | KEY_RIGHT = 262
398 | KEY_LEFT = 263
399 | KEY_DOWN = 264
400 | KEY_UP = 265
401 | KEY_PAGE_UP = 266
402 | KEY_PAGE_DOWN = 267
403 | KEY_HOME = 268
404 | KEY_END = 269
405 | KEY_CAPS_LOCK = 280
406 | KEY_SCROLL_LOCK = 281
407 | KEY_NUM_LOCK = 282
408 | KEY_PRINT_SCREEN = 283
409 | KEY_PAUSE = 284
410 | KEY_F1 = 290
411 | KEY_F2 = 291
412 | KEY_F3 = 292
413 | KEY_F4 = 293
414 | KEY_F5 = 294
415 | KEY_F6 = 295
416 | KEY_F7 = 296
417 | KEY_F8 = 297
418 | KEY_F9 = 298
419 | KEY_F10 = 299
420 | KEY_F11 = 300
421 | KEY_F12 = 301
422 | KEY_F13 = 302
423 | KEY_F14 = 303
424 | KEY_F15 = 304
425 | KEY_F16 = 305
426 | KEY_F17 = 306
427 | KEY_F18 = 307
428 | KEY_F19 = 308
429 | KEY_F20 = 309
430 | KEY_F21 = 310
431 | KEY_F22 = 311
432 | KEY_F23 = 312
433 | KEY_F24 = 313
434 | KEY_F25 = 314
435 | KEY_KP_0 = 320
436 | KEY_KP_1 = 321
437 | KEY_KP_2 = 322
438 | KEY_KP_3 = 323
439 | KEY_KP_4 = 324
440 | KEY_KP_5 = 325
441 | KEY_KP_6 = 326
442 | KEY_KP_7 = 327
443 | KEY_KP_8 = 328
444 | KEY_KP_9 = 329
445 | KEY_KP_DECIMAL = 330
446 | KEY_KP_DIVIDE = 331
447 | KEY_KP_MULTIPLY = 332
448 | KEY_KP_SUBTRACT = 333
449 | KEY_KP_ADD = 334
450 | KEY_KP_ENTER = 335
451 | KEY_KP_EQUAL = 336
452 | KEY_LEFT_SHIFT = 340
453 | KEY_LEFT_CONTROL = 341
454 | KEY_LEFT_ALT = 342
455 | KEY_LEFT_SUPER = 343
456 | KEY_RIGHT_SHIFT = 344
457 | KEY_RIGHT_CONTROL = 345
458 | KEY_RIGHT_ALT = 346
459 | KEY_RIGHT_SUPER = 347
460 | KEY_MENU = 348
461 | KEY_LAST = KEY_MENU
462 | MOD_SHIFT = 0x0001
463 | MOD_CONTROL = 0x0002
464 | MOD_ALT = 0x0004
465 | MOD_SUPER = 0x0008
466 | MOD_CAPS_LOCK = 0x0010
467 | MOD_NUM_LOCK = 0x0020
468 | MOUSE_BUTTON_1 = 0
469 | MOUSE_BUTTON_2 = 1
470 | MOUSE_BUTTON_3 = 2
471 | MOUSE_BUTTON_4 = 3
472 | MOUSE_BUTTON_5 = 4
473 | MOUSE_BUTTON_6 = 5
474 | MOUSE_BUTTON_7 = 6
475 | MOUSE_BUTTON_8 = 7
476 | MOUSE_BUTTON_LAST = MOUSE_BUTTON_8
477 | MOUSE_BUTTON_LEFT = MOUSE_BUTTON_1
478 | MOUSE_BUTTON_RIGHT = MOUSE_BUTTON_2
479 | MOUSE_BUTTON_MIDDLE = MOUSE_BUTTON_3
480 | JOYSTICK_1 = 0
481 | JOYSTICK_2 = 1
482 | JOYSTICK_3 = 2
483 | JOYSTICK_4 = 3
484 | JOYSTICK_5 = 4
485 | JOYSTICK_6 = 5
486 | JOYSTICK_7 = 6
487 | JOYSTICK_8 = 7
488 | JOYSTICK_9 = 8
489 | JOYSTICK_10 = 9
490 | JOYSTICK_11 = 10
491 | JOYSTICK_12 = 11
492 | JOYSTICK_13 = 12
493 | JOYSTICK_14 = 13
494 | JOYSTICK_15 = 14
495 | JOYSTICK_16 = 15
496 | JOYSTICK_LAST = JOYSTICK_16
497 | GAMEPAD_BUTTON_A = 0
498 | GAMEPAD_BUTTON_B = 1
499 | GAMEPAD_BUTTON_X = 2
500 | GAMEPAD_BUTTON_Y = 3
501 | GAMEPAD_BUTTON_LEFT_BUMPER = 4
502 | GAMEPAD_BUTTON_RIGHT_BUMPER = 5
503 | GAMEPAD_BUTTON_BACK = 6
504 | GAMEPAD_BUTTON_START = 7
505 | GAMEPAD_BUTTON_GUIDE = 8
506 | GAMEPAD_BUTTON_LEFT_THUMB = 9
507 | GAMEPAD_BUTTON_RIGHT_THUMB = 10
508 | GAMEPAD_BUTTON_DPAD_UP = 11
509 | GAMEPAD_BUTTON_DPAD_RIGHT = 12
510 | GAMEPAD_BUTTON_DPAD_DOWN = 13
511 | GAMEPAD_BUTTON_DPAD_LEFT = 14
512 | GAMEPAD_BUTTON_LAST = GAMEPAD_BUTTON_DPAD_LEFT
513 | GAMEPAD_BUTTON_CROSS = GAMEPAD_BUTTON_A
514 | GAMEPAD_BUTTON_CIRCLE = GAMEPAD_BUTTON_B
515 | GAMEPAD_BUTTON_SQUARE = GAMEPAD_BUTTON_X
516 | GAMEPAD_BUTTON_TRIANGLE = GAMEPAD_BUTTON_Y
517 | GAMEPAD_AXIS_LEFT_X = 0
518 | GAMEPAD_AXIS_LEFT_Y = 1
519 | GAMEPAD_AXIS_RIGHT_X = 2
520 | GAMEPAD_AXIS_RIGHT_Y = 3
521 | GAMEPAD_AXIS_LEFT_TRIGGER = 4
522 | GAMEPAD_AXIS_RIGHT_TRIGGER = 5
523 | GAMEPAD_AXIS_LAST = GAMEPAD_AXIS_RIGHT_TRIGGER
524 | NO_ERROR = 0
525 | NOT_INITIALIZED = 0x00010001
526 | NO_CURRENT_CONTEXT = 0x00010002
527 | INVALID_ENUM = 0x00010003
528 | INVALID_VALUE = 0x00010004
529 | OUT_OF_MEMORY = 0x00010005
530 | API_UNAVAILABLE = 0x00010006
531 | VERSION_UNAVAILABLE = 0x00010007
532 | PLATFORM_ERROR = 0x00010008
533 | FORMAT_UNAVAILABLE = 0x00010009
534 | NO_WINDOW_CONTEXT = 0x0001000A
535 | CURSOR_UNAVAILABLE = 0x0001000B
536 | FEATURE_UNAVAILABLE = 0x0001000C
537 | FEATURE_UNIMPLEMENTED = 0x0001000D
538 | PLATFORM_UNAVAILABLE = 0x0001000E
539 | FOCUSED = 0x00020001
540 | ICONIFIED = 0x00020002
541 | RESIZABLE = 0x00020003
542 | VISIBLE = 0x00020004
543 | DECORATED = 0x00020005
544 | AUTO_ICONIFY = 0x00020006
545 | FLOATING = 0x00020007
546 | MAXIMIZED = 0x00020008
547 | CENTER_CURSOR = 0x00020009
548 | TRANSPARENT_FRAMEBUFFER = 0x0002000A
549 | HOVERED = 0x0002000B
550 | FOCUS_ON_SHOW = 0x0002000C
551 | MOUSE_PASSTHROUGH = 0x0002000D
552 | POSITION_X = 0x0002000E
553 | POSITION_Y = 0x0002000F
554 | RED_BITS = 0x00021001
555 | GREEN_BITS = 0x00021002
556 | BLUE_BITS = 0x00021003
557 | ALPHA_BITS = 0x00021004
558 | DEPTH_BITS = 0x00021005
559 | STENCIL_BITS = 0x00021006
560 | ACCUM_RED_BITS = 0x00021007
561 | ACCUM_GREEN_BITS = 0x00021008
562 | ACCUM_BLUE_BITS = 0x00021009
563 | ACCUM_ALPHA_BITS = 0x0002100A
564 | AUX_BUFFERS = 0x0002100B
565 | STEREO = 0x0002100C
566 | SAMPLES = 0x0002100D
567 | SRGB_CAPABLE = 0x0002100E
568 | REFRESH_RATE = 0x0002100F
569 | DOUBLEBUFFER = 0x00021010
570 | CLIENT_API = 0x00022001
571 | CONTEXT_VERSION_MAJOR = 0x00022002
572 | CONTEXT_VERSION_MINOR = 0x00022003
573 | CONTEXT_REVISION = 0x00022004
574 | CONTEXT_ROBUSTNESS = 0x00022005
575 | OPENGL_FORWARD_COMPAT = 0x00022006
576 | OPENGL_DEBUG_CONTEXT = 0x00022007
577 | CONTEXT_DEBUG = 0x00022007
578 | OPENGL_PROFILE = 0x00022008
579 | CONTEXT_RELEASE_BEHAVIOR = 0x00022009
580 | CONTEXT_NO_ERROR = 0x0002200A
581 | CONTEXT_CREATION_API = 0x0002200B
582 | SCALE_TO_MONITOR = 0x0002200C
583 | SCALE_FRAMEBUFFER = 0x0002200D
584 | COCOA_RETINA_FRAMEBUFFER = 0x00023001
585 | COCOA_FRAME_NAME = 0x00023002
586 | COCOA_GRAPHICS_SWITCHING = 0x00023003
587 | X11_CLASS_NAME = 0x00024001
588 | X11_INSTANCE_NAME = 0x00024002
589 | WIN32_KEYBOARD_MENU = 0x00025001
590 | WIN32_SHOWDEFAULT = 0x00025002
591 | WAYLAND_APP_ID = 0x00026001
592 | NO_API = 0
593 | OPENGL_API = 0x00030001
594 | OPENGL_ES_API = 0x00030002
595 | NO_ROBUSTNESS = 0
596 | NO_RESET_NOTIFICATION = 0x00031001
597 | LOSE_CONTEXT_ON_RESET = 0x00031002
598 | OPENGL_ANY_PROFILE = 0
599 | OPENGL_CORE_PROFILE = 0x00032001
600 | OPENGL_COMPAT_PROFILE = 0x00032002
601 | CURSOR = 0x00033001
602 | STICKY_KEYS = 0x00033002
603 | STICKY_MOUSE_BUTTONS = 0x00033003
604 | LOCK_KEY_MODS = 0x00033004
605 | RAW_MOUSE_MOTION = 0x00033005
606 | CURSOR_NORMAL = 0x00034001
607 | CURSOR_HIDDEN = 0x00034002
608 | CURSOR_DISABLED = 0x00034003
609 | CURSOR_CAPTURED = 0x00034004
610 | ANY_RELEASE_BEHAVIOR = 0
611 | RELEASE_BEHAVIOR_FLUSH = 0x00035001
612 | RELEASE_BEHAVIOR_NONE = 0x00035002
613 | NATIVE_CONTEXT_API = 0x00036001
614 | EGL_CONTEXT_API = 0x00036002
615 | OSMESA_CONTEXT_API = 0x00036003
616 | ARROW_CURSOR = 0x00036001
617 | IBEAM_CURSOR = 0x00036002
618 | CROSSHAIR_CURSOR = 0x00036003
619 | HAND_CURSOR = 0x00036004
620 | POINTING_HAND_CURSOR = 0x00036004
621 | HRESIZE_CURSOR = 0x00036005
622 | RESIZE_EW_CURSOR = 0x00036005
623 | VRESIZE_CURSOR = 0x00036006
624 | RESIZE_NS_CURSOR = 0x00036006
625 | RESIZE_NWSE_CURSOR = 0x00036007
626 | RESIZE_NESW_CURSOR = 0x00036008
627 | RESIZE_ALL_CURSOR = 0x00036009
628 | NOT_ALLOWED_CURSOR = 0x0003600A
629 | ANGLE_PLATFORM_TYPE_NONE = 0x00037001
630 | ANGLE_PLATFORM_TYPE_OPENGL = 0x00037002
631 | ANGLE_PLATFORM_TYPE_OPENGLES = 0x00037003
632 | ANGLE_PLATFORM_TYPE_D3D9 = 0x00037004
633 | ANGLE_PLATFORM_TYPE_D3D11 = 0x00037005
634 | ANGLE_PLATFORM_TYPE_VULKAN = 0x00037007
635 | ANGLE_PLATFORM_TYPE_METAL = 0x00037008
636 | WAYLAND_PREFER_LIBDECOR = 0x00038001
637 | WAYLAND_DISABLE_LIBDECOR = 0x00038002
638 | CONNECTED = 0x00040001
639 | DISCONNECTED = 0x00040002
640 | JOYSTICK_HAT_BUTTONS = 0x00050001
641 | ANGLE_PLATFORM_TYPE = 0x00050002
642 | PLATFORM = 0x00050003
643 | COCOA_CHDIR_RESOURCES = 0x00051001
644 | COCOA_MENUBAR = 0x00051002
645 | X11_XCB_VULKAN_SURFACE = 0x00052001
646 | WAYLAND_LIBDECOR = 0x00053001
647 | ANY_PLATFORM = 0x00060000
648 | PLATFORM_WIN32 = 0x00060001
649 | PLATFORM_COCOA = 0x00060002
650 | PLATFORM_WAYLAND = 0x00060003
651 | PLATFORM_X11 = 0x00060004
652 | PLATFORM_NULL = 0x00060005
653 | ANY_POSITION = 0x80000000
654 | DONT_CARE = -1
655 |
656 | if _PREVIEW:
657 | UNLIMITED_MOUSE_BUTTONS = 0x00033006
658 |
659 |
660 | _exc_info_from_callback = None
661 | def _callback_exception_decorator(func):
662 | @functools.wraps(func)
663 | def callback_wrapper(*args, **kwargs):
664 | global _exc_info_from_callback
665 | if _exc_info_from_callback is not None:
666 | # We are on the way back to Python after an exception was raised.
667 | # Do not call further callbacks and wait for the errcheck function
668 | # to handle the exception first.
669 | return
670 | try:
671 | return func(*args, **kwargs)
672 | except (KeyboardInterrupt, SystemExit):
673 | raise
674 | except:
675 | _exc_info_from_callback = sys.exc_info()
676 | return callback_wrapper
677 |
678 |
679 | def _prepare_errcheck():
680 | """
681 | This function sets the errcheck attribute of all ctypes wrapped functions
682 | to evaluate the _exc_info_from_callback global variable and re-raise any
683 | exceptions that might have been raised in callbacks.
684 | It also modifies all callback types to automatically wrap the function
685 | using the _callback_exception_decorator.
686 | """
687 | def errcheck(result, *args):
688 | global _exc_info_from_callback
689 | if _exc_info_from_callback is not None:
690 | exc = _exc_info_from_callback
691 | _exc_info_from_callback = None
692 | _reraise(exc[1], exc[2])
693 | return result
694 |
695 | for symbol in dir(_glfw):
696 | if symbol.startswith('glfw'):
697 | getattr(_glfw, symbol).errcheck = errcheck
698 |
699 | _globals = globals()
700 | for symbol in _globals:
701 | if symbol.startswith('_GLFW') and symbol.endswith('fun'):
702 | def wrapper_cfunctype(func, cfunctype=_globals[symbol]):
703 | return cfunctype(_callback_exception_decorator(func))
704 | _globals[symbol] = wrapper_cfunctype
705 |
706 |
707 | _GLFWerrorfun = ctypes.CFUNCTYPE(None,
708 | ctypes.c_int,
709 | ctypes.c_char_p)
710 | _GLFWwindowposfun = ctypes.CFUNCTYPE(None,
711 | ctypes.POINTER(_GLFWwindow),
712 | ctypes.c_int,
713 | ctypes.c_int)
714 | _GLFWwindowsizefun = ctypes.CFUNCTYPE(None,
715 | ctypes.POINTER(_GLFWwindow),
716 | ctypes.c_int,
717 | ctypes.c_int)
718 | _GLFWwindowclosefun = ctypes.CFUNCTYPE(None,
719 | ctypes.POINTER(_GLFWwindow))
720 | _GLFWwindowrefreshfun = ctypes.CFUNCTYPE(None,
721 | ctypes.POINTER(_GLFWwindow))
722 | _GLFWwindowfocusfun = ctypes.CFUNCTYPE(None,
723 | ctypes.POINTER(_GLFWwindow),
724 | ctypes.c_int)
725 | _GLFWwindowiconifyfun = ctypes.CFUNCTYPE(None,
726 | ctypes.POINTER(_GLFWwindow),
727 | ctypes.c_int)
728 | _GLFWwindowmaximizefun = ctypes.CFUNCTYPE(None,
729 | ctypes.POINTER(_GLFWwindow),
730 | ctypes.c_int)
731 | _GLFWframebuffersizefun = ctypes.CFUNCTYPE(None,
732 | ctypes.POINTER(_GLFWwindow),
733 | ctypes.c_int,
734 | ctypes.c_int)
735 | _GLFWwindowcontentscalefun = ctypes.CFUNCTYPE(None,
736 | ctypes.POINTER(_GLFWwindow),
737 | ctypes.c_float,
738 | ctypes.c_float)
739 | _GLFWmousebuttonfun = ctypes.CFUNCTYPE(None,
740 | ctypes.POINTER(_GLFWwindow),
741 | ctypes.c_int,
742 | ctypes.c_int,
743 | ctypes.c_int)
744 | _GLFWcursorposfun = ctypes.CFUNCTYPE(None,
745 | ctypes.POINTER(_GLFWwindow),
746 | ctypes.c_double,
747 | ctypes.c_double)
748 | _GLFWcursorenterfun = ctypes.CFUNCTYPE(None,
749 | ctypes.POINTER(_GLFWwindow),
750 | ctypes.c_int)
751 | _GLFWscrollfun = ctypes.CFUNCTYPE(None,
752 | ctypes.POINTER(_GLFWwindow),
753 | ctypes.c_double,
754 | ctypes.c_double)
755 | _GLFWkeyfun = ctypes.CFUNCTYPE(None,
756 | ctypes.POINTER(_GLFWwindow),
757 | ctypes.c_int,
758 | ctypes.c_int,
759 | ctypes.c_int,
760 | ctypes.c_int)
761 | _GLFWcharfun = ctypes.CFUNCTYPE(None,
762 | ctypes.POINTER(_GLFWwindow),
763 | ctypes.c_int)
764 | _GLFWmonitorfun = ctypes.CFUNCTYPE(None,
765 | ctypes.POINTER(_GLFWmonitor),
766 | ctypes.c_int)
767 | _GLFWdropfun = ctypes.CFUNCTYPE(None,
768 | ctypes.POINTER(_GLFWwindow),
769 | ctypes.c_int,
770 | ctypes.POINTER(ctypes.c_char_p))
771 | _GLFWcharmodsfun = ctypes.CFUNCTYPE(None,
772 | ctypes.POINTER(_GLFWwindow),
773 | ctypes.c_uint,
774 | ctypes.c_int)
775 | _GLFWjoystickfun = ctypes.CFUNCTYPE(None,
776 | ctypes.c_int,
777 | ctypes.c_int)
778 |
779 | _GLFWallocatefun = ctypes.CFUNCTYPE(ctypes.c_void_p,
780 | ctypes.c_size_t,
781 | ctypes.c_void_p)
782 | _GLFWreallocatefun = ctypes.CFUNCTYPE(ctypes.c_void_p,
783 | ctypes.c_void_p,
784 | ctypes.c_size_t,
785 | ctypes.c_void_p)
786 | _GLFWdeallocatefun = ctypes.CFUNCTYPE(None,
787 | ctypes.c_void_p,
788 | ctypes.c_void_p)
789 |
790 |
791 | class _GLFWallocator(ctypes.Structure):
792 | """
793 | Wrapper for:
794 | typedef struct GLFWallocator GLFWallocator;
795 | """
796 | _fields_ = [
797 | ("allocate", _GLFWallocatefun),
798 | ("reallocate", _GLFWreallocatefun),
799 | ("deallocate", _GLFWdeallocatefun),
800 | ]
801 |
802 |
803 | _glfw.glfwInit.restype = ctypes.c_int
804 | _glfw.glfwInit.argtypes = []
805 | def init():
806 | """
807 | Initializes the GLFW library.
808 |
809 | Wrapper for:
810 | int glfwInit(void);
811 | """
812 | cwd = _getcwd()
813 | res = _glfw.glfwInit()
814 | os.chdir(cwd)
815 | return res
816 |
817 | _glfw.glfwTerminate.restype = None
818 | _glfw.glfwTerminate.argtypes = []
819 | def terminate():
820 | """
821 | Terminates the GLFW library.
822 |
823 | Wrapper for:
824 | void glfwTerminate(void);
825 | """
826 |
827 | for callback_repository in _callback_repositories:
828 | for window_addr in list(callback_repository.keys()):
829 | del callback_repository[window_addr]
830 | for window_addr in list(_window_user_data_repository.keys()):
831 | del _window_user_data_repository[window_addr]
832 | _glfw.glfwTerminate()
833 |
834 |
835 | if hasattr(_glfw, 'glfwInitHint'):
836 | _glfw.glfwInitHint.restype = None
837 | _glfw.glfwInitHint.argtypes = [ctypes.c_int,
838 | ctypes.c_int]
839 | def init_hint(hint, value):
840 | """
841 | Sets the specified init hint to the desired value.
842 |
843 | Wrapper for:
844 | void glfwInitHint(int hint, int value);
845 | """
846 | _glfw.glfwInitHint(hint, value)
847 |
848 |
849 | _glfw.glfwGetVersion.restype = None
850 | _glfw.glfwGetVersion.argtypes = [ctypes.POINTER(ctypes.c_int),
851 | ctypes.POINTER(ctypes.c_int),
852 | ctypes.POINTER(ctypes.c_int)]
853 | def get_version():
854 | """
855 | Retrieves the version of the GLFW library.
856 |
857 | Wrapper for:
858 | void glfwGetVersion(int* major, int* minor, int* rev);
859 | """
860 | major_value = ctypes.c_int(0)
861 | major = ctypes.pointer(major_value)
862 | minor_value = ctypes.c_int(0)
863 | minor = ctypes.pointer(minor_value)
864 | rev_value = ctypes.c_int(0)
865 | rev = ctypes.pointer(rev_value)
866 | _glfw.glfwGetVersion(major, minor, rev)
867 | return major_value.value, minor_value.value, rev_value.value
868 |
869 | _glfw.glfwGetVersionString.restype = ctypes.c_char_p
870 | _glfw.glfwGetVersionString.argtypes = []
871 | def get_version_string():
872 | """
873 | Returns a string describing the compile-time configuration.
874 |
875 | Wrapper for:
876 | const char* glfwGetVersionString(void);
877 | """
878 | return _glfw.glfwGetVersionString()
879 |
880 |
881 | if hasattr(_glfw, 'glfwGetError'):
882 | _glfw.glfwGetError.restype = ctypes.c_int
883 | _glfw.glfwGetError.argtypes = [ctypes.POINTER(ctypes.c_char_p)]
884 | def get_error():
885 | """
886 | Returns and clears the last error for the calling thread.
887 |
888 | Wrapper for:
889 | int glfwGetError(const char** description);
890 | """
891 | error_description = (ctypes.c_char_p * 1)()
892 | error_code = _glfw.glfwGetError(error_description)
893 | return error_code, error_description[0]
894 |
895 |
896 | @_callback_exception_decorator
897 | def _handle_glfw_errors(error_code, description):
898 | """
899 | Default error callback that raises GLFWError exceptions, issues GLFWError
900 | warnings or logs to the 'glfw' logger.
901 | Set an alternative error callback or set glfw.ERROR_REPORTING to False or
902 | 'ignore' to disable this behavior.
903 | """
904 | global ERROR_REPORTING
905 | message = "(%d) %s" % (error_code, description)
906 | error_reporting = ERROR_REPORTING
907 | if isinstance(error_reporting, dict):
908 | if error_code in error_reporting:
909 | error_reporting = error_reporting[error_code]
910 | elif None in error_reporting:
911 | error_reporting = error_reporting[None]
912 | else:
913 | error_reporting = None
914 | if error_reporting in ('raise', 'exception', True):
915 | raise GLFWError(message, error_code=error_code)
916 | elif error_reporting in ('warn', 'warning'):
917 | warnings.warn(message, GLFWError)
918 | elif error_reporting in ('log',):
919 | logging.getLogger('glfw').debug(message)
920 | elif error_reporting in ('ignore', False):
921 | pass
922 | else:
923 | raise ValueError('Invalid value of ERROR_REPORTING while handling GLFW error:\n' + message)
924 |
925 | _default_error_callback = _GLFWerrorfun(_handle_glfw_errors)
926 | _error_callback = (_handle_glfw_errors, _default_error_callback)
927 | _glfw.glfwSetErrorCallback.restype = _GLFWerrorfun
928 | _glfw.glfwSetErrorCallback.argtypes = [_GLFWerrorfun]
929 | _glfw.glfwSetErrorCallback(_default_error_callback)
930 | def set_error_callback(cbfun):
931 | """
932 | Sets the error callback.
933 |
934 | Wrapper for:
935 | GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun);
936 | """
937 | global _error_callback
938 | previous_callback = _error_callback
939 | if cbfun is None:
940 | cbfun = _handle_glfw_errors
941 | c_cbfun = _default_error_callback
942 | else:
943 | c_cbfun = _GLFWerrorfun(cbfun)
944 | _error_callback = (cbfun, c_cbfun)
945 | cbfun = c_cbfun
946 | _glfw.glfwSetErrorCallback(cbfun)
947 | if previous_callback is not None and previous_callback[0] != _handle_glfw_errors:
948 | return previous_callback[0]
949 |
950 | _glfw.glfwGetMonitors.restype = ctypes.POINTER(ctypes.POINTER(_GLFWmonitor))
951 | _glfw.glfwGetMonitors.argtypes = [ctypes.POINTER(ctypes.c_int)]
952 | def get_monitors():
953 | """
954 | Returns the currently connected monitors.
955 |
956 | Wrapper for:
957 | GLFWmonitor** glfwGetMonitors(int* count);
958 | """
959 | count_value = ctypes.c_int(0)
960 | count = ctypes.pointer(count_value)
961 | result = _glfw.glfwGetMonitors(count)
962 | monitors = [result[i] for i in range(count_value.value)]
963 | return monitors
964 |
965 | _glfw.glfwGetPrimaryMonitor.restype = ctypes.POINTER(_GLFWmonitor)
966 | _glfw.glfwGetPrimaryMonitor.argtypes = []
967 | def get_primary_monitor():
968 | """
969 | Returns the primary monitor.
970 |
971 | Wrapper for:
972 | GLFWmonitor* glfwGetPrimaryMonitor(void);
973 | """
974 | return _glfw.glfwGetPrimaryMonitor()
975 |
976 | _glfw.glfwGetMonitorPos.restype = None
977 | _glfw.glfwGetMonitorPos.argtypes = [ctypes.POINTER(_GLFWmonitor),
978 | ctypes.POINTER(ctypes.c_int),
979 | ctypes.POINTER(ctypes.c_int)]
980 | def get_monitor_pos(monitor):
981 | """
982 | Returns the position of the monitor's viewport on the virtual screen.
983 |
984 | Wrapper for:
985 | void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos);
986 | """
987 | xpos_value = ctypes.c_int(0)
988 | xpos = ctypes.pointer(xpos_value)
989 | ypos_value = ctypes.c_int(0)
990 | ypos = ctypes.pointer(ypos_value)
991 | _glfw.glfwGetMonitorPos(monitor, xpos, ypos)
992 | return xpos_value.value, ypos_value.value
993 |
994 |
995 | if hasattr(_glfw, 'glfwGetMonitorWorkarea'):
996 | _glfw.glfwGetMonitorWorkarea.restype = None
997 | _glfw.glfwGetMonitorWorkarea.argtypes = [ctypes.POINTER(_GLFWmonitor),
998 | ctypes.POINTER(ctypes.c_int),
999 | ctypes.POINTER(ctypes.c_int),
1000 | ctypes.POINTER(ctypes.c_int),
1001 | ctypes.POINTER(ctypes.c_int)]
1002 |
1003 |
1004 | def get_monitor_workarea(monitor):
1005 | """
1006 | Retrives the work area of the monitor.
1007 |
1008 | Wrapper for:
1009 | void glfwGetMonitorWorkarea(GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height);
1010 | """
1011 | xpos_value = ctypes.c_int(0)
1012 | xpos = ctypes.pointer(xpos_value)
1013 | ypos_value = ctypes.c_int(0)
1014 | ypos = ctypes.pointer(ypos_value)
1015 | width_value = ctypes.c_int(0)
1016 | width = ctypes.pointer(width_value)
1017 | height_value = ctypes.c_int(0)
1018 | height = ctypes.pointer(height_value)
1019 | _glfw.glfwGetMonitorWorkarea(monitor, xpos, ypos, width, height)
1020 | return (
1021 | xpos_value.value,
1022 | ypos_value.value,
1023 | width_value.value,
1024 | height_value.value
1025 | )
1026 |
1027 | _glfw.glfwGetMonitorPhysicalSize.restype = None
1028 | _glfw.glfwGetMonitorPhysicalSize.argtypes = [ctypes.POINTER(_GLFWmonitor),
1029 | ctypes.POINTER(ctypes.c_int),
1030 | ctypes.POINTER(ctypes.c_int)]
1031 | def get_monitor_physical_size(monitor):
1032 | """
1033 | Returns the physical size of the monitor.
1034 |
1035 | Wrapper for:
1036 | void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* width, int* height);
1037 | """
1038 | width_value = ctypes.c_int(0)
1039 | width = ctypes.pointer(width_value)
1040 | height_value = ctypes.c_int(0)
1041 | height = ctypes.pointer(height_value)
1042 | _glfw.glfwGetMonitorPhysicalSize(monitor, width, height)
1043 | return width_value.value, height_value.value
1044 |
1045 |
1046 | if hasattr(_glfw, 'glfwGetMonitorContentScale'):
1047 | _glfw.glfwGetMonitorContentScale.restype = None
1048 | _glfw.glfwGetMonitorContentScale.argtypes = [ctypes.POINTER(_GLFWmonitor),
1049 | ctypes.POINTER(ctypes.c_float),
1050 | ctypes.POINTER(ctypes.c_float)]
1051 | def get_monitor_content_scale(monitor):
1052 | """
1053 | Retrieves the content scale for the specified monitor.
1054 |
1055 | Wrapper for:
1056 | void glfwGetMonitorContentScale(GLFWmonitor* monitor, float* xscale, float* yscale);
1057 | """
1058 | xscale_value = ctypes.c_float(0)
1059 | xscale = ctypes.pointer(xscale_value)
1060 | yscale_value = ctypes.c_float(0)
1061 | yscale = ctypes.pointer(yscale_value)
1062 | _glfw.glfwGetMonitorContentScale(monitor, xscale, yscale)
1063 | return xscale_value.value, yscale_value.value
1064 |
1065 |
1066 | _glfw.glfwGetMonitorName.restype = ctypes.c_char_p
1067 | _glfw.glfwGetMonitorName.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1068 | def get_monitor_name(monitor):
1069 | """
1070 | Returns the name of the specified monitor.
1071 |
1072 | Wrapper for:
1073 | const char* glfwGetMonitorName(GLFWmonitor* monitor);
1074 | """
1075 | return _glfw.glfwGetMonitorName(monitor)
1076 |
1077 |
1078 | if hasattr(_glfw, 'glfwSetMonitorUserPointer') and hasattr(_glfw, 'glfwGetMonitorUserPointer'):
1079 | _monitor_user_data_repository = {}
1080 | _glfw.glfwSetMonitorUserPointer.restype = None
1081 | _glfw.glfwSetMonitorUserPointer.argtypes = [ctypes.POINTER(_GLFWmonitor),
1082 | ctypes.c_void_p]
1083 |
1084 |
1085 | def set_monitor_user_pointer(monitor, pointer):
1086 | """
1087 | Sets the user pointer of the specified monitor. You may pass a normal
1088 | python object into this function and it will be wrapped automatically.
1089 | The object will be kept in existence until the pointer is set to
1090 | something else.
1091 |
1092 | Wrapper for:
1093 | void glfwSetMonitorUserPointer(int jid, void* pointer);
1094 | """
1095 |
1096 | data = (False, pointer)
1097 | if not isinstance(pointer, ctypes.c_void_p):
1098 | data = (True, pointer)
1099 | # Create a void pointer for the python object
1100 | pointer = ctypes.cast(ctypes.pointer(ctypes.py_object(pointer)),
1101 | ctypes.c_void_p)
1102 |
1103 | monitor_addr = ctypes.cast(ctypes.pointer(monitor),
1104 | ctypes.POINTER(ctypes.c_long)).contents.value
1105 | _monitor_user_data_repository[monitor_addr] = data
1106 | _glfw.glfwSetMonitorUserPointer(monitor, pointer)
1107 |
1108 |
1109 | _glfw.glfwGetMonitorUserPointer.restype = ctypes.c_void_p
1110 | _glfw.glfwGetMonitorUserPointer.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1111 |
1112 |
1113 | def get_monitor_user_pointer(monitor):
1114 | """
1115 | Returns the user pointer of the specified monitor.
1116 |
1117 | Wrapper for:
1118 | void* glfwGetMonitorUserPointer(int jid);
1119 | """
1120 | monitor_addr = ctypes.cast(ctypes.pointer(monitor),
1121 | ctypes.POINTER(ctypes.c_long)).contents.value
1122 |
1123 | if monitor_addr in _monitor_user_data_repository:
1124 | data = _monitor_user_data_repository[monitor_addr]
1125 | is_wrapped_py_object = data[0]
1126 | if is_wrapped_py_object:
1127 | return data[1]
1128 | return _glfw.glfwGetMonitorUserPointer(monitor)
1129 |
1130 |
1131 | _monitor_callback = None
1132 | _glfw.glfwSetMonitorCallback.restype = _GLFWmonitorfun
1133 | _glfw.glfwSetMonitorCallback.argtypes = [_GLFWmonitorfun]
1134 | def set_monitor_callback(cbfun):
1135 | """
1136 | Sets the monitor configuration callback.
1137 |
1138 | Wrapper for:
1139 | GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun);
1140 | """
1141 | global _monitor_callback
1142 | previous_callback = _monitor_callback
1143 | if cbfun is None:
1144 | cbfun = 0
1145 | c_cbfun = _GLFWmonitorfun(cbfun)
1146 | _monitor_callback = (cbfun, c_cbfun)
1147 | cbfun = c_cbfun
1148 | _glfw.glfwSetMonitorCallback(cbfun)
1149 | if previous_callback is not None and previous_callback[0] != 0:
1150 | return previous_callback[0]
1151 |
1152 | _glfw.glfwGetVideoModes.restype = ctypes.POINTER(_GLFWvidmode)
1153 | _glfw.glfwGetVideoModes.argtypes = [ctypes.POINTER(_GLFWmonitor),
1154 | ctypes.POINTER(ctypes.c_int)]
1155 | def get_video_modes(monitor):
1156 | """
1157 | Returns the available video modes for the specified monitor.
1158 |
1159 | Wrapper for:
1160 | const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count);
1161 | """
1162 | count_value = ctypes.c_int(0)
1163 | count = ctypes.pointer(count_value)
1164 | result = _glfw.glfwGetVideoModes(monitor, count)
1165 | videomodes = [result[i].unwrap() for i in range(count_value.value)]
1166 | return videomodes
1167 |
1168 | _glfw.glfwGetVideoMode.restype = ctypes.POINTER(_GLFWvidmode)
1169 | _glfw.glfwGetVideoMode.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1170 | def get_video_mode(monitor):
1171 | """
1172 | Returns the current mode of the specified monitor.
1173 |
1174 | Wrapper for:
1175 | const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
1176 | """
1177 | videomode = _glfw.glfwGetVideoMode(monitor).contents
1178 | return videomode.unwrap()
1179 |
1180 | _glfw.glfwSetGamma.restype = None
1181 | _glfw.glfwSetGamma.argtypes = [ctypes.POINTER(_GLFWmonitor),
1182 | ctypes.c_float]
1183 | def set_gamma(monitor, gamma):
1184 | """
1185 | Generates a gamma ramp and sets it for the specified monitor.
1186 |
1187 | Wrapper for:
1188 | void glfwSetGamma(GLFWmonitor* monitor, float gamma);
1189 | """
1190 | _glfw.glfwSetGamma(monitor, gamma)
1191 |
1192 | _glfw.glfwGetGammaRamp.restype = ctypes.POINTER(_GLFWgammaramp)
1193 | _glfw.glfwGetGammaRamp.argtypes = [ctypes.POINTER(_GLFWmonitor)]
1194 | def get_gamma_ramp(monitor):
1195 | """
1196 | Retrieves the current gamma ramp for the specified monitor.
1197 |
1198 | Wrapper for:
1199 | const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
1200 | """
1201 | gammaramp = _glfw.glfwGetGammaRamp(monitor).contents
1202 | return gammaramp.unwrap()
1203 |
1204 | _glfw.glfwSetGammaRamp.restype = None
1205 | _glfw.glfwSetGammaRamp.argtypes = [ctypes.POINTER(_GLFWmonitor),
1206 | ctypes.POINTER(_GLFWgammaramp)]
1207 | def set_gamma_ramp(monitor, ramp):
1208 | """
1209 | Sets the current gamma ramp for the specified monitor.
1210 |
1211 | Wrapper for:
1212 | void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp);
1213 | """
1214 | gammaramp = _GLFWgammaramp()
1215 | gammaramp.wrap(ramp)
1216 | _glfw.glfwSetGammaRamp(monitor, ctypes.pointer(gammaramp))
1217 |
1218 | _glfw.glfwDefaultWindowHints.restype = None
1219 | _glfw.glfwDefaultWindowHints.argtypes = []
1220 | def default_window_hints():
1221 | """
1222 | Resets all window hints to their default values.
1223 |
1224 | Wrapper for:
1225 | void glfwDefaultWindowHints(void);
1226 | """
1227 | _glfw.glfwDefaultWindowHints()
1228 |
1229 | _glfw.glfwWindowHint.restype = None
1230 | _glfw.glfwWindowHint.argtypes = [ctypes.c_int,
1231 | ctypes.c_int]
1232 | def window_hint(hint, value):
1233 | """
1234 | Sets the specified window hint to the desired value.
1235 |
1236 | Wrapper for:
1237 | void glfwWindowHint(int hint, int value);
1238 | """
1239 | _glfw.glfwWindowHint(hint, value)
1240 |
1241 |
1242 | if hasattr(_glfw, 'glfwWindowHintString'):
1243 | _glfw.glfwWindowHintString.restype = None
1244 | _glfw.glfwWindowHintString.argtypes = [ctypes.c_int,
1245 | ctypes.c_char_p]
1246 | def window_hint_string(hint, value):
1247 | """
1248 | Sets the specified window hint to the desired value.
1249 |
1250 | Wrapper for:
1251 | void glfwWindowHintString(int hint, const char* value);
1252 | """
1253 | _glfw.glfwWindowHintString(hint, _to_char_p(value))
1254 |
1255 |
1256 | _glfw.glfwCreateWindow.restype = ctypes.POINTER(_GLFWwindow)
1257 | _glfw.glfwCreateWindow.argtypes = [ctypes.c_int,
1258 | ctypes.c_int,
1259 | ctypes.c_char_p,
1260 | ctypes.POINTER(_GLFWmonitor),
1261 | ctypes.POINTER(_GLFWwindow)]
1262 | def create_window(width, height, title, monitor, share):
1263 | """
1264 | Creates a window and its associated context.
1265 |
1266 | Wrapper for:
1267 | GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
1268 | """
1269 | return _glfw.glfwCreateWindow(width, height, _to_char_p(title),
1270 | monitor, share)
1271 |
1272 | _glfw.glfwDestroyWindow.restype = None
1273 | _glfw.glfwDestroyWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1274 | def destroy_window(window):
1275 | """
1276 | Destroys the specified window and its context.
1277 |
1278 | Wrapper for:
1279 | void glfwDestroyWindow(GLFWwindow* window);
1280 | """
1281 | _glfw.glfwDestroyWindow(window)
1282 | window_addr = ctypes.cast(ctypes.pointer(window),
1283 | ctypes.POINTER(ctypes.c_ulong)).contents.value
1284 | for callback_repository in _callback_repositories:
1285 | if window_addr in callback_repository:
1286 | del callback_repository[window_addr]
1287 | if window_addr in _window_user_data_repository:
1288 | del _window_user_data_repository[window_addr]
1289 |
1290 | _glfw.glfwWindowShouldClose.restype = ctypes.c_int
1291 | _glfw.glfwWindowShouldClose.argtypes = [ctypes.POINTER(_GLFWwindow)]
1292 | def window_should_close(window):
1293 | """
1294 | Checks the close flag of the specified window.
1295 |
1296 | Wrapper for:
1297 | int glfwWindowShouldClose(GLFWwindow* window);
1298 | """
1299 | return _glfw.glfwWindowShouldClose(window)
1300 |
1301 | _glfw.glfwSetWindowShouldClose.restype = None
1302 | _glfw.glfwSetWindowShouldClose.argtypes = [ctypes.POINTER(_GLFWwindow),
1303 | ctypes.c_int]
1304 | def set_window_should_close(window, value):
1305 | """
1306 | Sets the close flag of the specified window.
1307 |
1308 | Wrapper for:
1309 | void glfwSetWindowShouldClose(GLFWwindow* window, int value);
1310 | """
1311 | _glfw.glfwSetWindowShouldClose(window, value)
1312 |
1313 | _glfw.glfwSetWindowTitle.restype = None
1314 | _glfw.glfwSetWindowTitle.argtypes = [ctypes.POINTER(_GLFWwindow),
1315 | ctypes.c_char_p]
1316 | def set_window_title(window, title):
1317 | """
1318 | Sets the title of the specified window.
1319 |
1320 | Wrapper for:
1321 | void glfwSetWindowTitle(GLFWwindow* window, const char* title);
1322 | """
1323 | _glfw.glfwSetWindowTitle(window, _to_char_p(title))
1324 |
1325 | _glfw.glfwGetWindowPos.restype = None
1326 | _glfw.glfwGetWindowPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1327 | ctypes.POINTER(ctypes.c_int),
1328 | ctypes.POINTER(ctypes.c_int)]
1329 | def get_window_pos(window):
1330 | """
1331 | Retrieves the position of the client area of the specified window.
1332 |
1333 | Wrapper for:
1334 | void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
1335 | """
1336 | xpos_value = ctypes.c_int(0)
1337 | xpos = ctypes.pointer(xpos_value)
1338 | ypos_value = ctypes.c_int(0)
1339 | ypos = ctypes.pointer(ypos_value)
1340 | _glfw.glfwGetWindowPos(window, xpos, ypos)
1341 | return xpos_value.value, ypos_value.value
1342 |
1343 | _glfw.glfwSetWindowPos.restype = None
1344 | _glfw.glfwSetWindowPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1345 | ctypes.c_int,
1346 | ctypes.c_int]
1347 | def set_window_pos(window, xpos, ypos):
1348 | """
1349 | Sets the position of the client area of the specified window.
1350 |
1351 | Wrapper for:
1352 | void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos);
1353 | """
1354 | _glfw.glfwSetWindowPos(window, xpos, ypos)
1355 |
1356 | _glfw.glfwGetWindowSize.restype = None
1357 | _glfw.glfwGetWindowSize.argtypes = [ctypes.POINTER(_GLFWwindow),
1358 | ctypes.POINTER(ctypes.c_int),
1359 | ctypes.POINTER(ctypes.c_int)]
1360 | def get_window_size(window):
1361 | """
1362 | Retrieves the size of the client area of the specified window.
1363 |
1364 | Wrapper for:
1365 | void glfwGetWindowSize(GLFWwindow* window, int* width, int* height);
1366 | """
1367 | width_value = ctypes.c_int(0)
1368 | width = ctypes.pointer(width_value)
1369 | height_value = ctypes.c_int(0)
1370 | height = ctypes.pointer(height_value)
1371 | _glfw.glfwGetWindowSize(window, width, height)
1372 | return width_value.value, height_value.value
1373 |
1374 | _glfw.glfwSetWindowSize.restype = None
1375 | _glfw.glfwSetWindowSize.argtypes = [ctypes.POINTER(_GLFWwindow),
1376 | ctypes.c_int,
1377 | ctypes.c_int]
1378 | def set_window_size(window, width, height):
1379 | """
1380 | Sets the size of the client area of the specified window.
1381 |
1382 | Wrapper for:
1383 | void glfwSetWindowSize(GLFWwindow* window, int width, int height);
1384 | """
1385 | _glfw.glfwSetWindowSize(window, width, height)
1386 |
1387 | _glfw.glfwGetFramebufferSize.restype = None
1388 | _glfw.glfwGetFramebufferSize.argtypes = [ctypes.POINTER(_GLFWwindow),
1389 | ctypes.POINTER(ctypes.c_int),
1390 | ctypes.POINTER(ctypes.c_int)]
1391 | def get_framebuffer_size(window):
1392 | """
1393 | Retrieves the size of the framebuffer of the specified window.
1394 |
1395 | Wrapper for:
1396 | void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height);
1397 | """
1398 | width_value = ctypes.c_int(0)
1399 | width = ctypes.pointer(width_value)
1400 | height_value = ctypes.c_int(0)
1401 | height = ctypes.pointer(height_value)
1402 | _glfw.glfwGetFramebufferSize(window, width, height)
1403 | return width_value.value, height_value.value
1404 |
1405 |
1406 | if hasattr(_glfw, 'glfwGetWindowContentScale'):
1407 | _glfw.glfwGetWindowContentScale.restype = None
1408 | _glfw.glfwGetWindowContentScale.argtypes = [ctypes.POINTER(_GLFWwindow),
1409 | ctypes.POINTER(ctypes.c_float),
1410 | ctypes.POINTER(ctypes.c_float)]
1411 | def get_window_content_scale(window):
1412 | """
1413 | Retrieves the content scale for the specified window.
1414 |
1415 | Wrapper for:
1416 | void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale);
1417 | """
1418 | xscale_value = ctypes.c_float(0)
1419 | xscale = ctypes.pointer(xscale_value)
1420 | yscale_value = ctypes.c_float(0)
1421 | yscale = ctypes.pointer(yscale_value)
1422 | _glfw.glfwGetWindowContentScale(window, xscale, yscale)
1423 | return xscale_value.value, yscale_value.value
1424 |
1425 |
1426 | if hasattr(_glfw, 'glfwGetWindowOpacity'):
1427 | _glfw.glfwGetWindowOpacity.restype = ctypes.c_float
1428 | _glfw.glfwGetWindowOpacity.argtypes = [ctypes.POINTER(_GLFWwindow)]
1429 | def get_window_opacity(window):
1430 | """
1431 | Returns the opacity of the whole window.
1432 |
1433 | Wrapper for:
1434 | float glfwGetWindowOpacity(GLFWwindow* window);
1435 | """
1436 | return _glfw.glfwGetWindowOpacity(window)
1437 |
1438 |
1439 | if hasattr(_glfw, 'glfwSetWindowOpacity'):
1440 | _glfw.glfwSetWindowOpacity.restype = None
1441 | _glfw.glfwSetWindowOpacity.argtypes = [ctypes.POINTER(_GLFWwindow),
1442 | ctypes.c_float]
1443 | def set_window_opacity(window, opacity):
1444 | """
1445 | Sets the opacity of the whole window.
1446 |
1447 | Wrapper for:
1448 | void glfwSetWindowOpacity(GLFWwindow* window, float opacity);
1449 | """
1450 | opacity = ctypes.c_float(opacity)
1451 | _glfw.glfwSetWindowOpacity(window, opacity)
1452 |
1453 |
1454 | _glfw.glfwIconifyWindow.restype = None
1455 | _glfw.glfwIconifyWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1456 | def iconify_window(window):
1457 | """
1458 | Iconifies the specified window.
1459 |
1460 | Wrapper for:
1461 | void glfwIconifyWindow(GLFWwindow* window);
1462 | """
1463 | _glfw.glfwIconifyWindow(window)
1464 |
1465 | _glfw.glfwRestoreWindow.restype = None
1466 | _glfw.glfwRestoreWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1467 | def restore_window(window):
1468 | """
1469 | Restores the specified window.
1470 |
1471 | Wrapper for:
1472 | void glfwRestoreWindow(GLFWwindow* window);
1473 | """
1474 | _glfw.glfwRestoreWindow(window)
1475 |
1476 | _glfw.glfwShowWindow.restype = None
1477 | _glfw.glfwShowWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1478 | def show_window(window):
1479 | """
1480 | Makes the specified window visible.
1481 |
1482 | Wrapper for:
1483 | void glfwShowWindow(GLFWwindow* window);
1484 | """
1485 | _glfw.glfwShowWindow(window)
1486 |
1487 | _glfw.glfwHideWindow.restype = None
1488 | _glfw.glfwHideWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
1489 | def hide_window(window):
1490 | """
1491 | Hides the specified window.
1492 |
1493 | Wrapper for:
1494 | void glfwHideWindow(GLFWwindow* window);
1495 | """
1496 | _glfw.glfwHideWindow(window)
1497 |
1498 |
1499 | if hasattr(_glfw, 'glfwRequestWindowAttention'):
1500 | _glfw.glfwRequestWindowAttention.restype = None
1501 | _glfw.glfwRequestWindowAttention.argtypes = [ctypes.POINTER(_GLFWwindow)]
1502 | def request_window_attention(window):
1503 | """
1504 | Requests user attention to the specified window.
1505 |
1506 | Wrapper for:
1507 | void glfwRequestWindowAttention(GLFWwindow* window);
1508 | """
1509 | _glfw.glfwRequestWindowAttention(window)
1510 |
1511 |
1512 | _glfw.glfwGetWindowMonitor.restype = ctypes.POINTER(_GLFWmonitor)
1513 | _glfw.glfwGetWindowMonitor.argtypes = [ctypes.POINTER(_GLFWwindow)]
1514 | def get_window_monitor(window):
1515 | """
1516 | Returns the monitor that the window uses for full screen mode.
1517 |
1518 | Wrapper for:
1519 | GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
1520 | """
1521 | return _glfw.glfwGetWindowMonitor(window)
1522 |
1523 | _glfw.glfwGetWindowAttrib.restype = ctypes.c_int
1524 | _glfw.glfwGetWindowAttrib.argtypes = [ctypes.POINTER(_GLFWwindow),
1525 | ctypes.c_int]
1526 | def get_window_attrib(window, attrib):
1527 | """
1528 | Returns an attribute of the specified window.
1529 |
1530 | Wrapper for:
1531 | int glfwGetWindowAttrib(GLFWwindow* window, int attrib);
1532 | """
1533 | return _glfw.glfwGetWindowAttrib(window, attrib)
1534 |
1535 |
1536 | if hasattr(_glfw, 'glfwSetWindowAttrib'):
1537 | _glfw.glfwSetWindowAttrib.restype = None
1538 | _glfw.glfwSetWindowAttrib.argtypes = [ctypes.POINTER(_GLFWwindow),
1539 | ctypes.c_int,
1540 | ctypes.c_int]
1541 | def set_window_attrib(window, attrib, value):
1542 | """
1543 | Returns an attribute of the specified window.
1544 |
1545 | Wrapper for:
1546 | void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value);
1547 | """
1548 | _glfw.glfwSetWindowAttrib(window, attrib, value)
1549 |
1550 |
1551 | _window_user_data_repository = {}
1552 | _glfw.glfwSetWindowUserPointer.restype = None
1553 | _glfw.glfwSetWindowUserPointer.argtypes = [ctypes.POINTER(_GLFWwindow),
1554 | ctypes.c_void_p]
1555 | def set_window_user_pointer(window, pointer):
1556 | """
1557 | Sets the user pointer of the specified window. You may pass a normal python object into this function and it will
1558 | be wrapped automatically. The object will be kept in existence until the pointer is set to something else or
1559 | until the window is destroyed.
1560 |
1561 | Wrapper for:
1562 | void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer);
1563 | """
1564 |
1565 | data = (False, pointer)
1566 | if not isinstance(pointer, ctypes.c_void_p):
1567 | data = (True, pointer)
1568 | # Create a void pointer for the python object
1569 | pointer = ctypes.cast(ctypes.pointer(ctypes.py_object(pointer)), ctypes.c_void_p)
1570 |
1571 | window_addr = ctypes.cast(ctypes.pointer(window),
1572 | ctypes.POINTER(ctypes.c_long)).contents.value
1573 | _window_user_data_repository[window_addr] = data
1574 | _glfw.glfwSetWindowUserPointer(window, pointer)
1575 |
1576 | _glfw.glfwGetWindowUserPointer.restype = ctypes.c_void_p
1577 | _glfw.glfwGetWindowUserPointer.argtypes = [ctypes.POINTER(_GLFWwindow)]
1578 | def get_window_user_pointer(window):
1579 | """
1580 | Returns the user pointer of the specified window.
1581 |
1582 | Wrapper for:
1583 | void* glfwGetWindowUserPointer(GLFWwindow* window);
1584 | """
1585 |
1586 | window_addr = ctypes.cast(ctypes.pointer(window),
1587 | ctypes.POINTER(ctypes.c_long)).contents.value
1588 |
1589 | if window_addr in _window_user_data_repository:
1590 | data = _window_user_data_repository[window_addr]
1591 | is_wrapped_py_object = data[0]
1592 | if is_wrapped_py_object:
1593 | return data[1]
1594 | return _glfw.glfwGetWindowUserPointer(window)
1595 |
1596 | _window_pos_callback_repository = {}
1597 | _callback_repositories.append(_window_pos_callback_repository)
1598 | _glfw.glfwSetWindowPosCallback.restype = _GLFWwindowposfun
1599 | _glfw.glfwSetWindowPosCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1600 | _GLFWwindowposfun]
1601 | def set_window_pos_callback(window, cbfun):
1602 | """
1603 | Sets the position callback for the specified window.
1604 |
1605 | Wrapper for:
1606 | GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun);
1607 | """
1608 | window_addr = ctypes.cast(ctypes.pointer(window),
1609 | ctypes.POINTER(ctypes.c_long)).contents.value
1610 | if window_addr in _window_pos_callback_repository:
1611 | previous_callback = _window_pos_callback_repository[window_addr]
1612 | else:
1613 | previous_callback = None
1614 | if cbfun is None:
1615 | cbfun = 0
1616 | c_cbfun = _GLFWwindowposfun(cbfun)
1617 | _window_pos_callback_repository[window_addr] = (cbfun, c_cbfun)
1618 | cbfun = c_cbfun
1619 | _glfw.glfwSetWindowPosCallback(window, cbfun)
1620 | if previous_callback is not None and previous_callback[0] != 0:
1621 | return previous_callback[0]
1622 |
1623 | _window_size_callback_repository = {}
1624 | _callback_repositories.append(_window_size_callback_repository)
1625 | _glfw.glfwSetWindowSizeCallback.restype = _GLFWwindowsizefun
1626 | _glfw.glfwSetWindowSizeCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1627 | _GLFWwindowsizefun]
1628 | def set_window_size_callback(window, cbfun):
1629 | """
1630 | Sets the size callback for the specified window.
1631 |
1632 | Wrapper for:
1633 | GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);
1634 | """
1635 | window_addr = ctypes.cast(ctypes.pointer(window),
1636 | ctypes.POINTER(ctypes.c_long)).contents.value
1637 | if window_addr in _window_size_callback_repository:
1638 | previous_callback = _window_size_callback_repository[window_addr]
1639 | else:
1640 | previous_callback = None
1641 | if cbfun is None:
1642 | cbfun = 0
1643 | c_cbfun = _GLFWwindowsizefun(cbfun)
1644 | _window_size_callback_repository[window_addr] = (cbfun, c_cbfun)
1645 | cbfun = c_cbfun
1646 | _glfw.glfwSetWindowSizeCallback(window, cbfun)
1647 | if previous_callback is not None and previous_callback[0] != 0:
1648 | return previous_callback[0]
1649 |
1650 | _window_close_callback_repository = {}
1651 | _callback_repositories.append(_window_close_callback_repository)
1652 | _glfw.glfwSetWindowCloseCallback.restype = _GLFWwindowclosefun
1653 | _glfw.glfwSetWindowCloseCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1654 | _GLFWwindowclosefun]
1655 | def set_window_close_callback(window, cbfun):
1656 | """
1657 | Sets the close callback for the specified window.
1658 |
1659 | Wrapper for:
1660 | GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun);
1661 | """
1662 | window_addr = ctypes.cast(ctypes.pointer(window),
1663 | ctypes.POINTER(ctypes.c_long)).contents.value
1664 | if window_addr in _window_close_callback_repository:
1665 | previous_callback = _window_close_callback_repository[window_addr]
1666 | else:
1667 | previous_callback = None
1668 | if cbfun is None:
1669 | cbfun = 0
1670 | c_cbfun = _GLFWwindowclosefun(cbfun)
1671 | _window_close_callback_repository[window_addr] = (cbfun, c_cbfun)
1672 | cbfun = c_cbfun
1673 | _glfw.glfwSetWindowCloseCallback(window, cbfun)
1674 | if previous_callback is not None and previous_callback[0] != 0:
1675 | return previous_callback[0]
1676 |
1677 | _window_refresh_callback_repository = {}
1678 | _callback_repositories.append(_window_refresh_callback_repository)
1679 | _glfw.glfwSetWindowRefreshCallback.restype = _GLFWwindowrefreshfun
1680 | _glfw.glfwSetWindowRefreshCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1681 | _GLFWwindowrefreshfun]
1682 | def set_window_refresh_callback(window, cbfun):
1683 | """
1684 | Sets the refresh callback for the specified window.
1685 |
1686 | Wrapper for:
1687 | GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun);
1688 | """
1689 | window_addr = ctypes.cast(ctypes.pointer(window),
1690 | ctypes.POINTER(ctypes.c_long)).contents.value
1691 | if window_addr in _window_refresh_callback_repository:
1692 | previous_callback = _window_refresh_callback_repository[window_addr]
1693 | else:
1694 | previous_callback = None
1695 | if cbfun is None:
1696 | cbfun = 0
1697 | c_cbfun = _GLFWwindowrefreshfun(cbfun)
1698 | _window_refresh_callback_repository[window_addr] = (cbfun, c_cbfun)
1699 | cbfun = c_cbfun
1700 | _glfw.glfwSetWindowRefreshCallback(window, cbfun)
1701 | if previous_callback is not None and previous_callback[0] != 0:
1702 | return previous_callback[0]
1703 |
1704 | _window_focus_callback_repository = {}
1705 | _callback_repositories.append(_window_focus_callback_repository)
1706 | _glfw.glfwSetWindowFocusCallback.restype = _GLFWwindowfocusfun
1707 | _glfw.glfwSetWindowFocusCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1708 | _GLFWwindowfocusfun]
1709 | def set_window_focus_callback(window, cbfun):
1710 | """
1711 | Sets the focus callback for the specified window.
1712 |
1713 | Wrapper for:
1714 | GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun);
1715 | """
1716 | window_addr = ctypes.cast(ctypes.pointer(window),
1717 | ctypes.POINTER(ctypes.c_long)).contents.value
1718 | if window_addr in _window_focus_callback_repository:
1719 | previous_callback = _window_focus_callback_repository[window_addr]
1720 | else:
1721 | previous_callback = None
1722 | if cbfun is None:
1723 | cbfun = 0
1724 | c_cbfun = _GLFWwindowfocusfun(cbfun)
1725 | _window_focus_callback_repository[window_addr] = (cbfun, c_cbfun)
1726 | cbfun = c_cbfun
1727 | _glfw.glfwSetWindowFocusCallback(window, cbfun)
1728 | if previous_callback is not None and previous_callback[0] != 0:
1729 | return previous_callback[0]
1730 |
1731 | _window_iconify_callback_repository = {}
1732 | _callback_repositories.append(_window_iconify_callback_repository)
1733 | _glfw.glfwSetWindowIconifyCallback.restype = _GLFWwindowiconifyfun
1734 | _glfw.glfwSetWindowIconifyCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1735 | _GLFWwindowiconifyfun]
1736 | def set_window_iconify_callback(window, cbfun):
1737 | """
1738 | Sets the iconify callback for the specified window.
1739 |
1740 | Wrapper for:
1741 | GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
1742 | """
1743 | window_addr = ctypes.cast(ctypes.pointer(window),
1744 | ctypes.POINTER(ctypes.c_long)).contents.value
1745 | if window_addr in _window_iconify_callback_repository:
1746 | previous_callback = _window_iconify_callback_repository[window_addr]
1747 | else:
1748 | previous_callback = None
1749 | if cbfun is None:
1750 | cbfun = 0
1751 | c_cbfun = _GLFWwindowiconifyfun(cbfun)
1752 | _window_iconify_callback_repository[window_addr] = (cbfun, c_cbfun)
1753 | cbfun = c_cbfun
1754 | _glfw.glfwSetWindowIconifyCallback(window, cbfun)
1755 | if previous_callback is not None and previous_callback[0] != 0:
1756 | return previous_callback[0]
1757 |
1758 |
1759 | if hasattr(_glfw, 'glfwSetWindowMaximizeCallback'):
1760 | _window_maximize_callback_repository = {}
1761 | _callback_repositories.append(_window_maximize_callback_repository)
1762 | _glfw.glfwSetWindowMaximizeCallback.restype = _GLFWwindowmaximizefun
1763 | _glfw.glfwSetWindowMaximizeCallback.argtypes = [
1764 | ctypes.POINTER(_GLFWwindow),
1765 | _GLFWwindowmaximizefun
1766 | ]
1767 | def set_window_maximize_callback(window, cbfun):
1768 | """
1769 | Sets the maximize callback for the specified window.
1770 |
1771 | Wrapper for:
1772 | GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun cbfun);
1773 | """
1774 | window_addr = ctypes.cast(ctypes.pointer(window),
1775 | ctypes.POINTER(ctypes.c_long)).contents.value
1776 | if window_addr in _window_maximize_callback_repository:
1777 | previous_callback = _window_maximize_callback_repository[
1778 | window_addr]
1779 | else:
1780 | previous_callback = None
1781 | if cbfun is None:
1782 | cbfun = 0
1783 | c_cbfun = _GLFWwindowmaximizefun(cbfun)
1784 | _window_maximize_callback_repository[window_addr] = (cbfun, c_cbfun)
1785 | cbfun = c_cbfun
1786 | _glfw.glfwSetWindowMaximizeCallback(window, cbfun)
1787 | if previous_callback is not None and previous_callback[0] != 0:
1788 | return previous_callback[0]
1789 |
1790 |
1791 | _framebuffer_size_callback_repository = {}
1792 | _callback_repositories.append(_framebuffer_size_callback_repository)
1793 | _glfw.glfwSetFramebufferSizeCallback.restype = _GLFWframebuffersizefun
1794 | _glfw.glfwSetFramebufferSizeCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1795 | _GLFWframebuffersizefun]
1796 | def set_framebuffer_size_callback(window, cbfun):
1797 | """
1798 | Sets the framebuffer resize callback for the specified window.
1799 |
1800 | Wrapper for:
1801 | GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun cbfun);
1802 | """
1803 | window_addr = ctypes.cast(ctypes.pointer(window),
1804 | ctypes.POINTER(ctypes.c_long)).contents.value
1805 | if window_addr in _framebuffer_size_callback_repository:
1806 | previous_callback = _framebuffer_size_callback_repository[window_addr]
1807 | else:
1808 | previous_callback = None
1809 | if cbfun is None:
1810 | cbfun = 0
1811 | c_cbfun = _GLFWframebuffersizefun(cbfun)
1812 | _framebuffer_size_callback_repository[window_addr] = (cbfun, c_cbfun)
1813 | cbfun = c_cbfun
1814 | _glfw.glfwSetFramebufferSizeCallback(window, cbfun)
1815 | if previous_callback is not None and previous_callback[0] != 0:
1816 | return previous_callback[0]
1817 |
1818 |
1819 | if hasattr(_glfw, 'glfwSetWindowContentScaleCallback'):
1820 | _window_content_scale_callback_repository = {}
1821 | _callback_repositories.append(_window_content_scale_callback_repository)
1822 | _glfw.glfwSetWindowContentScaleCallback.restype = _GLFWwindowcontentscalefun
1823 | _glfw.glfwSetWindowContentScaleCallback.argtypes = [
1824 | ctypes.POINTER(_GLFWwindow),
1825 | _GLFWwindowcontentscalefun]
1826 |
1827 |
1828 | def set_window_content_scale_callback(window, cbfun):
1829 | """
1830 | Sets the window content scale callback for the specified window.
1831 |
1832 | Wrapper for:
1833 | GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun cbfun);
1834 | """
1835 | window_addr = ctypes.cast(ctypes.pointer(window),
1836 | ctypes.POINTER(ctypes.c_long)).contents.value
1837 | if window_addr in _window_content_scale_callback_repository:
1838 | previous_callback = _window_content_scale_callback_repository[
1839 | window_addr]
1840 | else:
1841 | previous_callback = None
1842 | if cbfun is None:
1843 | cbfun = 0
1844 | c_cbfun = _GLFWwindowcontentscalefun(cbfun)
1845 | _window_content_scale_callback_repository[window_addr] = (cbfun, c_cbfun)
1846 | cbfun = c_cbfun
1847 | _glfw.glfwSetWindowContentScaleCallback(window, cbfun)
1848 | if previous_callback is not None and previous_callback[0] != 0:
1849 | return previous_callback[0]
1850 |
1851 |
1852 | _glfw.glfwPollEvents.restype = None
1853 | _glfw.glfwPollEvents.argtypes = []
1854 | def poll_events():
1855 | """
1856 | Processes all pending events.
1857 |
1858 | Wrapper for:
1859 | void glfwPollEvents(void);
1860 | """
1861 | _glfw.glfwPollEvents()
1862 |
1863 | _glfw.glfwWaitEvents.restype = None
1864 | _glfw.glfwWaitEvents.argtypes = []
1865 | def wait_events():
1866 | """
1867 | Waits until events are pending and processes them.
1868 |
1869 | Wrapper for:
1870 | void glfwWaitEvents(void);
1871 | """
1872 | _glfw.glfwWaitEvents()
1873 |
1874 | _glfw.glfwGetInputMode.restype = ctypes.c_int
1875 | _glfw.glfwGetInputMode.argtypes = [ctypes.POINTER(_GLFWwindow),
1876 | ctypes.c_int]
1877 | def get_input_mode(window, mode):
1878 | """
1879 | Returns the value of an input option for the specified window.
1880 |
1881 | Wrapper for:
1882 | int glfwGetInputMode(GLFWwindow* window, int mode);
1883 | """
1884 | return _glfw.glfwGetInputMode(window, mode)
1885 |
1886 | _glfw.glfwSetInputMode.restype = None
1887 | _glfw.glfwSetInputMode.argtypes = [ctypes.POINTER(_GLFWwindow),
1888 | ctypes.c_int,
1889 | ctypes.c_int]
1890 | def set_input_mode(window, mode, value):
1891 | """
1892 | Sets an input option for the specified window.
1893 | @param[in] window The window whose input mode to set.
1894 | @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS` or
1895 | `GLFW_STICKY_MOUSE_BUTTONS`.
1896 | @param[in] value The new value of the specified input mode.
1897 |
1898 | Wrapper for:
1899 | void glfwSetInputMode(GLFWwindow* window, int mode, int value);
1900 | """
1901 | _glfw.glfwSetInputMode(window, mode, value)
1902 |
1903 |
1904 | if hasattr(_glfw, 'glfwRawMouseMotionSupported'):
1905 | _glfw.glfwRawMouseMotionSupported.restype = ctypes.c_int
1906 | _glfw.glfwRawMouseMotionSupported.argtypes = []
1907 | def raw_mouse_motion_supported():
1908 | """
1909 | Returns whether raw mouse motion is supported.
1910 |
1911 | Wrapper for:
1912 | int glfwRawMouseMotionSupported(void);
1913 | """
1914 | return _glfw.glfwRawMouseMotionSupported() != 0
1915 |
1916 |
1917 | _glfw.glfwGetKey.restype = ctypes.c_int
1918 | _glfw.glfwGetKey.argtypes = [ctypes.POINTER(_GLFWwindow),
1919 | ctypes.c_int]
1920 | def get_key(window, key):
1921 | """
1922 | Returns the last reported state of a keyboard key for the specified
1923 | window.
1924 |
1925 | Wrapper for:
1926 | int glfwGetKey(GLFWwindow* window, int key);
1927 | """
1928 | return _glfw.glfwGetKey(window, key)
1929 |
1930 | _glfw.glfwGetMouseButton.restype = ctypes.c_int
1931 | _glfw.glfwGetMouseButton.argtypes = [ctypes.POINTER(_GLFWwindow),
1932 | ctypes.c_int]
1933 | def get_mouse_button(window, button):
1934 | """
1935 | Returns the last reported state of a mouse button for the specified
1936 | window.
1937 |
1938 | Wrapper for:
1939 | int glfwGetMouseButton(GLFWwindow* window, int button);
1940 | """
1941 | return _glfw.glfwGetMouseButton(window, button)
1942 |
1943 | _glfw.glfwGetCursorPos.restype = None
1944 | _glfw.glfwGetCursorPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1945 | ctypes.POINTER(ctypes.c_double),
1946 | ctypes.POINTER(ctypes.c_double)]
1947 | def get_cursor_pos(window):
1948 | """
1949 | Retrieves the last reported cursor position, relative to the client
1950 | area of the window.
1951 |
1952 | Wrapper for:
1953 | void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
1954 | """
1955 | xpos_value = ctypes.c_double(0.0)
1956 | xpos = ctypes.pointer(xpos_value)
1957 | ypos_value = ctypes.c_double(0.0)
1958 | ypos = ctypes.pointer(ypos_value)
1959 | _glfw.glfwGetCursorPos(window, xpos, ypos)
1960 | return xpos_value.value, ypos_value.value
1961 |
1962 | _glfw.glfwSetCursorPos.restype = None
1963 | _glfw.glfwSetCursorPos.argtypes = [ctypes.POINTER(_GLFWwindow),
1964 | ctypes.c_double,
1965 | ctypes.c_double]
1966 | def set_cursor_pos(window, xpos, ypos):
1967 | """
1968 | Sets the position of the cursor, relative to the client area of the window.
1969 |
1970 | Wrapper for:
1971 | void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
1972 | """
1973 | _glfw.glfwSetCursorPos(window, xpos, ypos)
1974 |
1975 | _key_callback_repository = {}
1976 | _callback_repositories.append(_key_callback_repository)
1977 | _glfw.glfwSetKeyCallback.restype = _GLFWkeyfun
1978 | _glfw.glfwSetKeyCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
1979 | _GLFWkeyfun]
1980 | def set_key_callback(window, cbfun):
1981 | """
1982 | Sets the key callback.
1983 |
1984 | Wrapper for:
1985 | GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
1986 | """
1987 | window_addr = ctypes.cast(ctypes.pointer(window),
1988 | ctypes.POINTER(ctypes.c_long)).contents.value
1989 | if window_addr in _key_callback_repository:
1990 | previous_callback = _key_callback_repository[window_addr]
1991 | else:
1992 | previous_callback = None
1993 | if cbfun is None:
1994 | cbfun = 0
1995 | c_cbfun = _GLFWkeyfun(cbfun)
1996 | _key_callback_repository[window_addr] = (cbfun, c_cbfun)
1997 | cbfun = c_cbfun
1998 | _glfw.glfwSetKeyCallback(window, cbfun)
1999 | if previous_callback is not None and previous_callback[0] != 0:
2000 | return previous_callback[0]
2001 |
2002 | _char_callback_repository = {}
2003 | _callback_repositories.append(_char_callback_repository)
2004 | _glfw.glfwSetCharCallback.restype = _GLFWcharfun
2005 | _glfw.glfwSetCharCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2006 | _GLFWcharfun]
2007 | def set_char_callback(window, cbfun):
2008 | """
2009 | Sets the Unicode character callback.
2010 |
2011 | Wrapper for:
2012 | GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun);
2013 | """
2014 | window_addr = ctypes.cast(ctypes.pointer(window),
2015 | ctypes.POINTER(ctypes.c_long)).contents.value
2016 | if window_addr in _char_callback_repository:
2017 | previous_callback = _char_callback_repository[window_addr]
2018 | else:
2019 | previous_callback = None
2020 | if cbfun is None:
2021 | cbfun = 0
2022 | c_cbfun = _GLFWcharfun(cbfun)
2023 | _char_callback_repository[window_addr] = (cbfun, c_cbfun)
2024 | cbfun = c_cbfun
2025 | _glfw.glfwSetCharCallback(window, cbfun)
2026 | if previous_callback is not None and previous_callback[0] != 0:
2027 | return previous_callback[0]
2028 |
2029 | _mouse_button_callback_repository = {}
2030 | _callback_repositories.append(_mouse_button_callback_repository)
2031 | _glfw.glfwSetMouseButtonCallback.restype = _GLFWmousebuttonfun
2032 | _glfw.glfwSetMouseButtonCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2033 | _GLFWmousebuttonfun]
2034 | def set_mouse_button_callback(window, cbfun):
2035 | """
2036 | Sets the mouse button callback.
2037 |
2038 | Wrapper for:
2039 | GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
2040 | """
2041 | window_addr = ctypes.cast(ctypes.pointer(window),
2042 | ctypes.POINTER(ctypes.c_long)).contents.value
2043 | if window_addr in _mouse_button_callback_repository:
2044 | previous_callback = _mouse_button_callback_repository[window_addr]
2045 | else:
2046 | previous_callback = None
2047 | if cbfun is None:
2048 | cbfun = 0
2049 | c_cbfun = _GLFWmousebuttonfun(cbfun)
2050 | _mouse_button_callback_repository[window_addr] = (cbfun, c_cbfun)
2051 | cbfun = c_cbfun
2052 | _glfw.glfwSetMouseButtonCallback(window, cbfun)
2053 | if previous_callback is not None and previous_callback[0] != 0:
2054 | return previous_callback[0]
2055 |
2056 | _cursor_pos_callback_repository = {}
2057 | _callback_repositories.append(_cursor_pos_callback_repository)
2058 | _glfw.glfwSetCursorPosCallback.restype = _GLFWcursorposfun
2059 | _glfw.glfwSetCursorPosCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2060 | _GLFWcursorposfun]
2061 | def set_cursor_pos_callback(window, cbfun):
2062 | """
2063 | Sets the cursor position callback.
2064 |
2065 | Wrapper for:
2066 | GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun);
2067 | """
2068 | window_addr = ctypes.cast(ctypes.pointer(window),
2069 | ctypes.POINTER(ctypes.c_long)).contents.value
2070 | if window_addr in _cursor_pos_callback_repository:
2071 | previous_callback = _cursor_pos_callback_repository[window_addr]
2072 | else:
2073 | previous_callback = None
2074 | if cbfun is None:
2075 | cbfun = 0
2076 | c_cbfun = _GLFWcursorposfun(cbfun)
2077 | _cursor_pos_callback_repository[window_addr] = (cbfun, c_cbfun)
2078 | cbfun = c_cbfun
2079 | _glfw.glfwSetCursorPosCallback(window, cbfun)
2080 | if previous_callback is not None and previous_callback[0] != 0:
2081 | return previous_callback[0]
2082 |
2083 | _cursor_enter_callback_repository = {}
2084 | _callback_repositories.append(_cursor_enter_callback_repository)
2085 | _glfw.glfwSetCursorEnterCallback.restype = _GLFWcursorenterfun
2086 | _glfw.glfwSetCursorEnterCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2087 | _GLFWcursorenterfun]
2088 | def set_cursor_enter_callback(window, cbfun):
2089 | """
2090 | Sets the cursor enter/exit callback.
2091 |
2092 | Wrapper for:
2093 | GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun cbfun);
2094 | """
2095 | window_addr = ctypes.cast(ctypes.pointer(window),
2096 | ctypes.POINTER(ctypes.c_long)).contents.value
2097 | if window_addr in _cursor_enter_callback_repository:
2098 | previous_callback = _cursor_enter_callback_repository[window_addr]
2099 | else:
2100 | previous_callback = None
2101 | if cbfun is None:
2102 | cbfun = 0
2103 | c_cbfun = _GLFWcursorenterfun(cbfun)
2104 | _cursor_enter_callback_repository[window_addr] = (cbfun, c_cbfun)
2105 | cbfun = c_cbfun
2106 | _glfw.glfwSetCursorEnterCallback(window, cbfun)
2107 | if previous_callback is not None and previous_callback[0] != 0:
2108 | return previous_callback[0]
2109 |
2110 | _scroll_callback_repository = {}
2111 | _callback_repositories.append(_scroll_callback_repository)
2112 | _glfw.glfwSetScrollCallback.restype = _GLFWscrollfun
2113 | _glfw.glfwSetScrollCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2114 | _GLFWscrollfun]
2115 | def set_scroll_callback(window, cbfun):
2116 | """
2117 | Sets the scroll callback.
2118 |
2119 | Wrapper for:
2120 | GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);
2121 | """
2122 | window_addr = ctypes.cast(ctypes.pointer(window),
2123 | ctypes.POINTER(ctypes.c_long)).contents.value
2124 | if window_addr in _scroll_callback_repository:
2125 | previous_callback = _scroll_callback_repository[window_addr]
2126 | else:
2127 | previous_callback = None
2128 | if cbfun is None:
2129 | cbfun = 0
2130 | c_cbfun = _GLFWscrollfun(cbfun)
2131 | _scroll_callback_repository[window_addr] = (cbfun, c_cbfun)
2132 | cbfun = c_cbfun
2133 | _glfw.glfwSetScrollCallback(window, cbfun)
2134 | if previous_callback is not None and previous_callback[0] != 0:
2135 | return previous_callback[0]
2136 |
2137 | _glfw.glfwJoystickPresent.restype = ctypes.c_int
2138 | _glfw.glfwJoystickPresent.argtypes = [ctypes.c_int]
2139 | def joystick_present(joy):
2140 | """
2141 | Returns whether the specified joystick is present.
2142 |
2143 | Wrapper for:
2144 | int glfwJoystickPresent(int joy);
2145 | """
2146 | return _glfw.glfwJoystickPresent(joy)
2147 |
2148 | _glfw.glfwGetJoystickAxes.restype = ctypes.POINTER(ctypes.c_float)
2149 | _glfw.glfwGetJoystickAxes.argtypes = [ctypes.c_int,
2150 | ctypes.POINTER(ctypes.c_int)]
2151 | def get_joystick_axes(joy):
2152 | """
2153 | Returns the values of all axes of the specified joystick.
2154 |
2155 | Wrapper for:
2156 | const float* glfwGetJoystickAxes(int joy, int* count);
2157 | """
2158 | count_value = ctypes.c_int(0)
2159 | count = ctypes.pointer(count_value)
2160 | result = _glfw.glfwGetJoystickAxes(joy, count)
2161 | return result, count_value.value
2162 |
2163 | _glfw.glfwGetJoystickButtons.restype = ctypes.POINTER(ctypes.c_ubyte)
2164 | _glfw.glfwGetJoystickButtons.argtypes = [ctypes.c_int,
2165 | ctypes.POINTER(ctypes.c_int)]
2166 | def get_joystick_buttons(joy):
2167 | """
2168 | Returns the state of all buttons of the specified joystick.
2169 |
2170 | Wrapper for:
2171 | const unsigned char* glfwGetJoystickButtons(int joy, int* count);
2172 | """
2173 | count_value = ctypes.c_int(0)
2174 | count = ctypes.pointer(count_value)
2175 | result = _glfw.glfwGetJoystickButtons(joy, count)
2176 | return result, count_value.value
2177 |
2178 |
2179 | if hasattr(_glfw, 'glfwGetJoystickHats'):
2180 | _glfw.glfwGetJoystickHats.restype = ctypes.POINTER(ctypes.c_ubyte)
2181 | _glfw.glfwGetJoystickHats.argtypes = [ctypes.c_int,
2182 | ctypes.POINTER(ctypes.c_int)]
2183 | def get_joystick_hats(joystick_id):
2184 | """
2185 | Returns the state of all hats of the specified joystick.
2186 |
2187 | Wrapper for:
2188 | const unsigned char* glfwGetJoystickButtons(int joy, int* count);
2189 | """
2190 | count_value = ctypes.c_int(0)
2191 | count = ctypes.pointer(count_value)
2192 | result = _glfw.glfwGetJoystickHats(joystick_id, count)
2193 | return result, count_value.value
2194 |
2195 |
2196 | _glfw.glfwGetJoystickName.restype = ctypes.c_char_p
2197 | _glfw.glfwGetJoystickName.argtypes = [ctypes.c_int]
2198 | def get_joystick_name(joy):
2199 | """
2200 | Returns the name of the specified joystick.
2201 |
2202 | Wrapper for:
2203 | const char* glfwGetJoystickName(int joy);
2204 | """
2205 | return _glfw.glfwGetJoystickName(joy)
2206 |
2207 |
2208 | if hasattr(_glfw, 'glfwGetJoystickGUID'):
2209 | _glfw.glfwGetJoystickGUID.restype = ctypes.c_char_p
2210 | _glfw.glfwGetJoystickGUID.argtypes = [ctypes.c_int]
2211 | def get_joystick_guid(joystick_id):
2212 | """
2213 | Returns the SDL compatible GUID of the specified joystick.
2214 |
2215 | Wrapper for:
2216 | const char* glfwGetJoystickGUID(int jid);
2217 | """
2218 | return _glfw.glfwGetJoystickGUID(joystick_id)
2219 |
2220 | if hasattr(_glfw, 'glfwSetJoystickUserPointer') and hasattr(_glfw, 'glfwGetJoystickUserPointer'):
2221 | _joystick_user_data_repository = {}
2222 | _glfw.glfwSetJoystickUserPointer.restype = None
2223 | _glfw.glfwSetJoystickUserPointer.argtypes = [ctypes.c_int,
2224 | ctypes.c_void_p]
2225 |
2226 |
2227 | def set_joystick_user_pointer(joystick_id, pointer):
2228 | """
2229 | Sets the user pointer of the specified joystick. You may pass a normal
2230 | python object into this function and it will be wrapped automatically.
2231 | The object will be kept in existence until the pointer is set to
2232 | something else.
2233 |
2234 | Wrapper for:
2235 | void glfwSetJoystickUserPointer(int jid, void* pointer);
2236 | """
2237 |
2238 | data = (False, pointer)
2239 | if not isinstance(pointer, ctypes.c_void_p):
2240 | data = (True, pointer)
2241 | # Create a void pointer for the python object
2242 | pointer = ctypes.cast(ctypes.pointer(ctypes.py_object(pointer)),
2243 | ctypes.c_void_p)
2244 |
2245 | _joystick_user_data_repository[joystick_id] = data
2246 | _glfw.glfwSetWindowUserPointer(joystick_id, pointer)
2247 |
2248 |
2249 | _glfw.glfwGetJoystickUserPointer.restype = ctypes.c_void_p
2250 | _glfw.glfwGetJoystickUserPointer.argtypes = [ctypes.c_int]
2251 |
2252 |
2253 | def get_joystick_user_pointer(joystick_id):
2254 | """
2255 | Returns the user pointer of the specified joystick.
2256 |
2257 | Wrapper for:
2258 | void* glfwGetJoystickUserPointer(int jid);
2259 | """
2260 |
2261 | if joystick_id in _joystick_user_data_repository:
2262 | data = _joystick_user_data_repository[joystick_id]
2263 | is_wrapped_py_object = data[0]
2264 | if is_wrapped_py_object:
2265 | return data[1]
2266 | return _glfw.glfwGetJoystickUserPointer(joystick_id)
2267 |
2268 |
2269 | if hasattr(_glfw, 'glfwJoystickIsGamepad'):
2270 | _glfw.glfwJoystickIsGamepad.restype = ctypes.c_int
2271 | _glfw.glfwJoystickIsGamepad.argtypes = [ctypes.c_int]
2272 | def joystick_is_gamepad(joystick_id):
2273 | """
2274 | Returns whether the specified joystick has a gamepad mapping.
2275 |
2276 | Wrapper for:
2277 | int glfwJoystickIsGamepad(int jid);
2278 | """
2279 | return _glfw.glfwJoystickIsGamepad(joystick_id) != 0
2280 |
2281 |
2282 | if hasattr(_glfw, 'glfwGetGamepadState'):
2283 | _glfw.glfwGetGamepadState.restype = ctypes.c_int
2284 | _glfw.glfwGetGamepadState.argtypes = [ctypes.c_int,
2285 | ctypes.POINTER(_GLFWgamepadstate)]
2286 | def get_gamepad_state(joystick_id):
2287 | """
2288 | Retrieves the state of the specified joystick remapped as a gamepad.
2289 |
2290 | Wrapper for:
2291 | int glfwGetGamepadState(int jid, GLFWgamepadstate* state);
2292 | """
2293 | gamepad_state = _GLFWgamepadstate()
2294 | if _glfw.glfwGetGamepadState(joystick_id, ctypes.byref(gamepad_state)) == FALSE:
2295 | return None
2296 | return gamepad_state.unwrap()
2297 |
2298 |
2299 | _glfw.glfwSetClipboardString.restype = None
2300 | _glfw.glfwSetClipboardString.argtypes = [ctypes.POINTER(_GLFWwindow),
2301 | ctypes.c_char_p]
2302 | def set_clipboard_string(window, string):
2303 | """
2304 | Sets the clipboard to the specified string.
2305 |
2306 | Wrapper for:
2307 | void glfwSetClipboardString(GLFWwindow* window, const char* string);
2308 | """
2309 | if window is not None:
2310 | warnings.warn("The window parameter to glfwSetClipboardString is deprecated", DeprecationWarning, stacklevel=2)
2311 | _glfw.glfwSetClipboardString(window, _to_char_p(string))
2312 |
2313 | _glfw.glfwGetClipboardString.restype = ctypes.c_char_p
2314 | _glfw.glfwGetClipboardString.argtypes = [ctypes.POINTER(_GLFWwindow)]
2315 | def get_clipboard_string(window):
2316 | """
2317 | Retrieves the contents of the clipboard as a string.
2318 |
2319 | Wrapper for:
2320 | const char* glfwGetClipboardString(GLFWwindow* window);
2321 | """
2322 | if window is not None:
2323 | warnings.warn("The window parameter to glfwSetClipboardString is deprecated", DeprecationWarning, stacklevel=2)
2324 | return _glfw.glfwGetClipboardString(window)
2325 |
2326 | _glfw.glfwGetTime.restype = ctypes.c_double
2327 | _glfw.glfwGetTime.argtypes = []
2328 | def get_time():
2329 | """
2330 | Returns the value of the GLFW timer.
2331 |
2332 | Wrapper for:
2333 | double glfwGetTime(void);
2334 | """
2335 | return _glfw.glfwGetTime()
2336 |
2337 | _glfw.glfwSetTime.restype = None
2338 | _glfw.glfwSetTime.argtypes = [ctypes.c_double]
2339 | def set_time(time):
2340 | """
2341 | Sets the GLFW timer.
2342 |
2343 | Wrapper for:
2344 | void glfwSetTime(double time);
2345 | """
2346 | _glfw.glfwSetTime(time)
2347 |
2348 | _glfw.glfwMakeContextCurrent.restype = None
2349 | _glfw.glfwMakeContextCurrent.argtypes = [ctypes.POINTER(_GLFWwindow)]
2350 | def make_context_current(window):
2351 | """
2352 | Makes the context of the specified window current for the calling
2353 | thread.
2354 |
2355 | Wrapper for:
2356 | void glfwMakeContextCurrent(GLFWwindow* window);
2357 | """
2358 | _glfw.glfwMakeContextCurrent(window)
2359 |
2360 | _glfw.glfwGetCurrentContext.restype = ctypes.POINTER(_GLFWwindow)
2361 | _glfw.glfwGetCurrentContext.argtypes = []
2362 | def get_current_context():
2363 | """
2364 | Returns the window whose context is current on the calling thread.
2365 |
2366 | Wrapper for:
2367 | GLFWwindow* glfwGetCurrentContext(void);
2368 | """
2369 | return _glfw.glfwGetCurrentContext()
2370 |
2371 | _glfw.glfwSwapBuffers.restype = None
2372 | _glfw.glfwSwapBuffers.argtypes = [ctypes.POINTER(_GLFWwindow)]
2373 | def swap_buffers(window):
2374 | """
2375 | Swaps the front and back buffers of the specified window.
2376 |
2377 | Wrapper for:
2378 | void glfwSwapBuffers(GLFWwindow* window);
2379 | """
2380 | _glfw.glfwSwapBuffers(window)
2381 |
2382 | _glfw.glfwSwapInterval.restype = None
2383 | _glfw.glfwSwapInterval.argtypes = [ctypes.c_int]
2384 | def swap_interval(interval):
2385 | """
2386 | Sets the swap interval for the current context.
2387 |
2388 | Wrapper for:
2389 | void glfwSwapInterval(int interval);
2390 | """
2391 | _glfw.glfwSwapInterval(interval)
2392 |
2393 | _glfw.glfwExtensionSupported.restype = ctypes.c_int
2394 | _glfw.glfwExtensionSupported.argtypes = [ctypes.c_char_p]
2395 | def extension_supported(extension):
2396 | """
2397 | Returns whether the specified extension is available.
2398 |
2399 | Wrapper for:
2400 | int glfwExtensionSupported(const char* extension);
2401 | """
2402 | return _glfw.glfwExtensionSupported(_to_char_p(extension))
2403 |
2404 | _glfw.glfwGetProcAddress.restype = ctypes.c_void_p
2405 | _glfw.glfwGetProcAddress.argtypes = [ctypes.c_char_p]
2406 | def get_proc_address(procname):
2407 | """
2408 | Returns the address of the specified function for the current
2409 | context.
2410 |
2411 | Wrapper for:
2412 | GLFWglproc glfwGetProcAddress(const char* procname);
2413 | """
2414 | return _glfw.glfwGetProcAddress(_to_char_p(procname))
2415 |
2416 | if hasattr(_glfw, 'glfwSetDropCallback'):
2417 | _window_drop_callback_repository = {}
2418 | _callback_repositories.append(_window_drop_callback_repository)
2419 | _glfw.glfwSetDropCallback.restype = _GLFWdropfun
2420 | _glfw.glfwSetDropCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2421 | _GLFWdropfun]
2422 | def set_drop_callback(window, cbfun):
2423 | """
2424 | Sets the file drop callback.
2425 |
2426 | Wrapper for:
2427 | GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
2428 | """
2429 | window_addr = ctypes.cast(ctypes.pointer(window),
2430 | ctypes.POINTER(ctypes.c_long)).contents.value
2431 | if window_addr in _window_drop_callback_repository:
2432 | previous_callback = _window_drop_callback_repository[window_addr]
2433 | else:
2434 | previous_callback = None
2435 | if cbfun is None:
2436 | cbfun = 0
2437 | else:
2438 | def cb_wrapper(window, count, c_paths, cbfun=cbfun):
2439 | paths = [c_paths[i].decode('utf-8') for i in range(count)]
2440 | cbfun(window, paths)
2441 | cbfun = cb_wrapper
2442 | c_cbfun = _GLFWdropfun(cbfun)
2443 | _window_drop_callback_repository[window_addr] = (cbfun, c_cbfun)
2444 | cbfun = c_cbfun
2445 | _glfw.glfwSetDropCallback(window, cbfun)
2446 | if previous_callback is not None and previous_callback[0] != 0:
2447 | return previous_callback[0]
2448 |
2449 | if hasattr(_glfw, 'glfwSetCharModsCallback'):
2450 | _window_char_mods_callback_repository = {}
2451 | _callback_repositories.append(_window_char_mods_callback_repository)
2452 | _glfw.glfwSetCharModsCallback.restype = _GLFWcharmodsfun
2453 | _glfw.glfwSetCharModsCallback.argtypes = [ctypes.POINTER(_GLFWwindow),
2454 | _GLFWcharmodsfun]
2455 | def set_char_mods_callback(window, cbfun):
2456 | """
2457 | Sets the Unicode character with modifiers callback.
2458 |
2459 | Wrapper for:
2460 | GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun cbfun);
2461 | """
2462 | warnings.warn("glfwSetCharModsCallback is scheduled for removal in GLFW 4.0", DeprecationWarning, stacklevel=2)
2463 | window_addr = ctypes.cast(ctypes.pointer(window),
2464 | ctypes.POINTER(ctypes.c_long)).contents.value
2465 | if window_addr in _window_char_mods_callback_repository:
2466 | previous_callback = _window_char_mods_callback_repository[window_addr]
2467 | else:
2468 | previous_callback = None
2469 | if cbfun is None:
2470 | cbfun = 0
2471 | c_cbfun = _GLFWcharmodsfun(cbfun)
2472 | _window_char_mods_callback_repository[window_addr] = (cbfun, c_cbfun)
2473 | cbfun = c_cbfun
2474 | _glfw.glfwSetCharModsCallback(window, cbfun)
2475 | if previous_callback is not None and previous_callback[0] != 0:
2476 | return previous_callback[0]
2477 |
2478 | if hasattr(_glfw, 'glfwVulkanSupported'):
2479 | _glfw.glfwVulkanSupported.restype = ctypes.c_int
2480 | _glfw.glfwVulkanSupported.argtypes = []
2481 | def vulkan_supported():
2482 | """
2483 | Returns whether the Vulkan loader has been found.
2484 |
2485 | Wrapper for:
2486 | int glfwVulkanSupported(void);
2487 | """
2488 | return _glfw.glfwVulkanSupported() != 0
2489 |
2490 | if hasattr(_glfw, 'glfwGetRequiredInstanceExtensions'):
2491 | _glfw.glfwGetRequiredInstanceExtensions.restype = ctypes.POINTER(ctypes.c_char_p)
2492 | _glfw.glfwGetRequiredInstanceExtensions.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
2493 | def get_required_instance_extensions():
2494 | """
2495 | Returns the Vulkan instance extensions required by GLFW.
2496 |
2497 | Wrapper for:
2498 | const char** glfwGetRequiredInstanceExtensions(uint32_t* count);
2499 | """
2500 | count_value = ctypes.c_uint32(0)
2501 | count = ctypes.pointer(count_value)
2502 | c_extensions = _glfw.glfwGetRequiredInstanceExtensions(count)
2503 | count = count_value.value
2504 | extensions = [c_extensions[i].decode('utf-8') for i in range(count)]
2505 | return extensions
2506 |
2507 | if hasattr(_glfw, 'glfwGetTimerValue'):
2508 | _glfw.glfwGetTimerValue.restype = ctypes.c_uint64
2509 | _glfw.glfwGetTimerValue.argtypes = []
2510 | def get_timer_value():
2511 | """
2512 | Returns the current value of the raw timer.
2513 |
2514 | Wrapper for:
2515 | uint64_t glfwGetTimerValue(void);
2516 | """
2517 | return int(_glfw.glfwGetTimerValue())
2518 |
2519 | if hasattr(_glfw, 'glfwGetTimerFrequency'):
2520 | _glfw.glfwGetTimerFrequency.restype = ctypes.c_uint64
2521 | _glfw.glfwGetTimerFrequency.argtypes = []
2522 | def get_timer_frequency():
2523 | """
2524 | Returns the frequency, in Hz, of the raw timer.
2525 |
2526 | Wrapper for:
2527 | uint64_t glfwGetTimerFrequency(void);
2528 | """
2529 | return int(_glfw.glfwGetTimerFrequency())
2530 |
2531 |
2532 | if hasattr(_glfw, 'glfwSetJoystickCallback'):
2533 | _joystick_callback = None
2534 | _glfw.glfwSetJoystickCallback.restype = _GLFWjoystickfun
2535 | _glfw.glfwSetJoystickCallback.argtypes = [_GLFWjoystickfun]
2536 | def set_joystick_callback(cbfun):
2537 | """
2538 | Sets the error callback.
2539 |
2540 | Wrapper for:
2541 | GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun cbfun);
2542 | """
2543 | global _joystick_callback
2544 | previous_callback = _error_callback
2545 | if cbfun is None:
2546 | cbfun = 0
2547 | c_cbfun = _GLFWjoystickfun(cbfun)
2548 | _joystick_callback = (cbfun, c_cbfun)
2549 | cbfun = c_cbfun
2550 | _glfw.glfwSetJoystickCallback(cbfun)
2551 | if previous_callback is not None and previous_callback[0] != 0:
2552 | return previous_callback[0]
2553 |
2554 |
2555 | if hasattr(_glfw, 'glfwUpdateGamepadMappings'):
2556 | _glfw.glfwUpdateGamepadMappings.restype = ctypes.c_int
2557 | _glfw.glfwUpdateGamepadMappings.argtypes = [ctypes.c_char_p]
2558 | def update_gamepad_mappings(string):
2559 | """
2560 | Adds the specified SDL_GameControllerDB gamepad mappings.
2561 |
2562 | Wrapper for:
2563 | int glfwUpdateGamepadMappings(const char* string);
2564 | """
2565 | return _glfw.glfwUpdateGamepadMappings(_to_char_p(string))
2566 |
2567 |
2568 | if hasattr(_glfw, 'glfwGetGamepadName'):
2569 | _glfw.glfwGetGamepadName.restype = ctypes.c_char_p
2570 | _glfw.glfwGetGamepadName.argtypes = [ctypes.c_int]
2571 | def get_gamepad_name(joystick_id):
2572 | """
2573 | Returns the human-readable gamepad name for the specified joystick.
2574 |
2575 | Wrapper for:
2576 | const char* glfwGetGamepadName(int jid);
2577 | """
2578 | gamepad_name = _glfw.glfwGetGamepadName(joystick_id)
2579 | if gamepad_name:
2580 | return gamepad_name.decode('utf-8')
2581 | return None
2582 |
2583 |
2584 | if hasattr(_glfw, 'glfwGetKeyName'):
2585 | _glfw.glfwGetKeyName.restype = ctypes.c_char_p
2586 | _glfw.glfwGetKeyName.argtypes = [ctypes.c_int, ctypes.c_int]
2587 | def get_key_name(key, scancode):
2588 | """
2589 | Returns the localized name of the specified printable key.
2590 |
2591 | Wrapper for:
2592 | const char* glfwGetKeyName(int key, int scancode);
2593 | """
2594 | key_name = _glfw.glfwGetKeyName(key, scancode)
2595 | if key_name:
2596 | return key_name.decode('utf-8')
2597 | return None
2598 |
2599 |
2600 | if hasattr(_glfw, 'glfwGetKeyScancode'):
2601 | _glfw.glfwGetKeyScancode.restype = ctypes.c_int
2602 | _glfw.glfwGetKeyScancode.argtypes = [ctypes.c_int]
2603 | def get_key_scancode(key):
2604 | """
2605 | Returns the platform-specific scancode of the specified key.
2606 |
2607 | Wrapper for:
2608 | int glfwGetKeyScancode(int key);
2609 | """
2610 | return _glfw.glfwGetKeyScancode(key)
2611 |
2612 |
2613 | if hasattr(_glfw, 'glfwCreateCursor'):
2614 | _glfw.glfwCreateCursor.restype = ctypes.POINTER(_GLFWcursor)
2615 | _glfw.glfwCreateCursor.argtypes = [ctypes.POINTER(_GLFWimage),
2616 | ctypes.c_int,
2617 | ctypes.c_int]
2618 | def create_cursor(image, xhot, yhot):
2619 | """
2620 | Creates a custom cursor.
2621 |
2622 | Wrapper for:
2623 | GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot);
2624 | """
2625 | c_image = _GLFWimage()
2626 | c_image.wrap(image)
2627 | return _glfw.glfwCreateCursor(ctypes.pointer(c_image), xhot, yhot)
2628 |
2629 | if hasattr(_glfw, 'glfwCreateStandardCursor'):
2630 | _glfw.glfwCreateStandardCursor.restype = ctypes.POINTER(_GLFWcursor)
2631 | _glfw.glfwCreateStandardCursor.argtypes = [ctypes.c_int]
2632 | def create_standard_cursor(shape):
2633 | """
2634 | Creates a cursor with a standard shape.
2635 |
2636 | Wrapper for:
2637 | GLFWcursor* glfwCreateStandardCursor(int shape);
2638 | """
2639 | return _glfw.glfwCreateStandardCursor(shape)
2640 |
2641 | if hasattr(_glfw, 'glfwDestroyCursor'):
2642 | _glfw.glfwDestroyCursor.restype = None
2643 | _glfw.glfwDestroyCursor.argtypes = [ctypes.POINTER(_GLFWcursor)]
2644 | def destroy_cursor(cursor):
2645 | """
2646 | Destroys a cursor.
2647 |
2648 | Wrapper for:
2649 | void glfwDestroyCursor(GLFWcursor* cursor);
2650 | """
2651 | _glfw.glfwDestroyCursor(cursor)
2652 |
2653 | if hasattr(_glfw, 'glfwSetCursor'):
2654 | _glfw.glfwSetCursor.restype = None
2655 | _glfw.glfwSetCursor.argtypes = [ctypes.POINTER(_GLFWwindow),
2656 | ctypes.POINTER(_GLFWcursor)]
2657 | def set_cursor(window, cursor):
2658 | """
2659 | Sets the cursor for the window.
2660 |
2661 | Wrapper for:
2662 | void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
2663 | """
2664 | _glfw.glfwSetCursor(window, cursor)
2665 |
2666 | if hasattr(_glfw, 'glfwCreateWindowSurface'):
2667 | _glfw.glfwCreateWindowSurface.restype = ctypes.c_int
2668 | _glfw.glfwCreateWindowSurface.argtypes = [ctypes.c_void_p,
2669 | ctypes.POINTER(_GLFWwindow),
2670 | ctypes.c_void_p,
2671 | ctypes.c_void_p]
2672 | def create_window_surface(instance, window, allocator, surface):
2673 | """
2674 | Creates a Vulkan surface for the specified window.
2675 |
2676 | Wrapper for:
2677 | VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
2678 | """
2679 | instance = _cffi_to_ctypes_void_p(instance)
2680 | surface = _cffi_to_ctypes_void_p(surface)
2681 | allocator = _cffi_to_ctypes_void_p(allocator)
2682 | return _glfw.glfwCreateWindowSurface(instance, window, allocator, surface)
2683 |
2684 | if hasattr(_glfw, 'glfwGetPhysicalDevicePresentationSupport'):
2685 | _glfw.glfwGetPhysicalDevicePresentationSupport.restype = ctypes.c_int
2686 | _glfw.glfwGetPhysicalDevicePresentationSupport.argtypes = [ctypes.c_void_p,
2687 | ctypes.c_void_p,
2688 | ctypes.c_uint32]
2689 | def get_physical_device_presentation_support(instance, device, queuefamily):
2690 | """
2691 | Creates a Vulkan surface for the specified window.
2692 |
2693 | Wrapper for:
2694 | int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
2695 | """
2696 | instance = _cffi_to_ctypes_void_p(instance)
2697 | device = _cffi_to_ctypes_void_p(device)
2698 | return _glfw.glfwGetPhysicalDevicePresentationSupport(instance, device, queuefamily)
2699 |
2700 | if hasattr(_glfw, 'glfwGetInstanceProcAddress'):
2701 | _glfw.glfwGetInstanceProcAddress.restype = ctypes.c_void_p
2702 | _glfw.glfwGetInstanceProcAddress.argtypes = [ctypes.c_void_p,
2703 | ctypes.c_char_p]
2704 | def get_instance_proc_address(instance, procname):
2705 | """
2706 | Returns the address of the specified Vulkan instance function.
2707 |
2708 | Wrapper for:
2709 | GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname);
2710 | """
2711 | instance = _cffi_to_ctypes_void_p(instance)
2712 | return _glfw.glfwGetInstanceProcAddress(instance, procname)
2713 |
2714 | if hasattr(_glfw, 'glfwSetWindowIcon'):
2715 | _glfw.glfwSetWindowIcon.restype = None
2716 | _glfw.glfwSetWindowIcon.argtypes = [ctypes.POINTER(_GLFWwindow),
2717 | ctypes.c_int,
2718 | ctypes.POINTER(_GLFWimage)]
2719 |
2720 | def set_window_icon(window, count, images):
2721 | """
2722 | Sets the icon for the specified window.
2723 |
2724 | Wrapper for:
2725 | void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images);
2726 | """
2727 | if count == 1 and (not hasattr(images, '__len__') or len(images) == 3):
2728 | # Stay compatible to calls passing a single icon
2729 | images = [images]
2730 | array_type = _GLFWimage * count
2731 | _images = array_type()
2732 | for i, image in enumerate(images):
2733 | _images[i].wrap(image)
2734 | _glfw.glfwSetWindowIcon(window, count, _images)
2735 |
2736 | if hasattr(_glfw, 'glfwSetWindowSizeLimits'):
2737 | _glfw.glfwSetWindowSizeLimits.restype = None
2738 | _glfw.glfwSetWindowSizeLimits.argtypes = [ctypes.POINTER(_GLFWwindow),
2739 | ctypes.c_int, ctypes.c_int,
2740 | ctypes.c_int, ctypes.c_int]
2741 |
2742 | def set_window_size_limits(window,
2743 | minwidth, minheight,
2744 | maxwidth, maxheight):
2745 | """
2746 | Sets the size limits of the specified window.
2747 |
2748 | Wrapper for:
2749 | void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight);
2750 | """
2751 | _glfw.glfwSetWindowSizeLimits(window,
2752 | minwidth, minheight,
2753 | maxwidth, maxheight)
2754 |
2755 | if hasattr(_glfw, 'glfwSetWindowAspectRatio'):
2756 | _glfw.glfwSetWindowAspectRatio.restype = None
2757 | _glfw.glfwSetWindowAspectRatio.argtypes = [ctypes.POINTER(_GLFWwindow),
2758 | ctypes.c_int, ctypes.c_int]
2759 | def set_window_aspect_ratio(window, numer, denom):
2760 | """
2761 | Sets the aspect ratio of the specified window.
2762 |
2763 | Wrapper for:
2764 | void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom);
2765 | """
2766 | _glfw.glfwSetWindowAspectRatio(window, numer, denom)
2767 |
2768 | if hasattr(_glfw, 'glfwGetWindowFrameSize'):
2769 | _glfw.glfwGetWindowFrameSize.restype = None
2770 | _glfw.glfwGetWindowFrameSize.argtypes = [ctypes.POINTER(_GLFWwindow),
2771 | ctypes.POINTER(ctypes.c_int),
2772 | ctypes.POINTER(ctypes.c_int),
2773 | ctypes.POINTER(ctypes.c_int),
2774 | ctypes.POINTER(ctypes.c_int)]
2775 | def get_window_frame_size(window):
2776 | """
2777 | Retrieves the size of the frame of the window.
2778 |
2779 | Wrapper for:
2780 | void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom);
2781 | """
2782 | left = ctypes.c_int(0)
2783 | top = ctypes.c_int(0)
2784 | right = ctypes.c_int(0)
2785 | bottom = ctypes.c_int(0)
2786 | _glfw.glfwGetWindowFrameSize(window,
2787 | ctypes.pointer(left),
2788 | ctypes.pointer(top),
2789 | ctypes.pointer(right),
2790 | ctypes.pointer(bottom))
2791 | return left.value, top.value, right.value, bottom.value
2792 |
2793 | if hasattr(_glfw, 'glfwMaximizeWindow'):
2794 | _glfw.glfwMaximizeWindow.restype = None
2795 | _glfw.glfwMaximizeWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
2796 | def maximize_window(window):
2797 | """
2798 | Maximizes the specified window.
2799 |
2800 | Wrapper for:
2801 | void glfwMaximizeWindow(GLFWwindow* window);
2802 | """
2803 | _glfw.glfwMaximizeWindow(window)
2804 |
2805 | if hasattr(_glfw, 'glfwFocusWindow'):
2806 | _glfw.glfwFocusWindow.restype = None
2807 | _glfw.glfwFocusWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
2808 | def focus_window(window):
2809 | """
2810 | Brings the specified window to front and sets input focus.
2811 |
2812 | Wrapper for:
2813 | void glfwFocusWindow(GLFWwindow* window);
2814 | """
2815 | _glfw.glfwFocusWindow(window)
2816 |
2817 | if hasattr(_glfw, 'glfwSetWindowMonitor'):
2818 | _glfw.glfwSetWindowMonitor.restype = None
2819 | _glfw.glfwSetWindowMonitor.argtypes = [ctypes.POINTER(_GLFWwindow),
2820 | ctypes.POINTER(_GLFWmonitor),
2821 | ctypes.c_int,
2822 | ctypes.c_int,
2823 | ctypes.c_int,
2824 | ctypes.c_int,
2825 | ctypes.c_int]
2826 | def set_window_monitor(window, monitor, xpos, ypos, width, height,
2827 | refresh_rate):
2828 | """
2829 | Sets the mode, monitor, video mode and placement of a window.
2830 |
2831 | Wrapper for:
2832 | void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate);
2833 | """
2834 | _glfw.glfwSetWindowMonitor(window, monitor,
2835 | xpos, ypos, width, height, refresh_rate)
2836 |
2837 | if hasattr(_glfw, 'glfwWaitEventsTimeout'):
2838 | _glfw.glfwWaitEventsTimeout.restype = None
2839 | _glfw.glfwWaitEventsTimeout.argtypes = [ctypes.c_double]
2840 | def wait_events_timeout(timeout):
2841 | """
2842 | Waits with timeout until events are queued and processes them.
2843 |
2844 | Wrapper for:
2845 | void glfwWaitEventsTimeout(double timeout);
2846 | """
2847 | _glfw.glfwWaitEventsTimeout(timeout)
2848 |
2849 | if hasattr(_glfw, 'glfwPostEmptyEvent'):
2850 | _glfw.glfwPostEmptyEvent.restype = None
2851 | _glfw.glfwPostEmptyEvent.argtypes = []
2852 | def post_empty_event():
2853 | """
2854 | Posts an empty event to the event queue.
2855 |
2856 | Wrapper for:
2857 | void glfwPostEmptyEvent();
2858 | """
2859 | _glfw.glfwPostEmptyEvent()
2860 |
2861 |
2862 | if hasattr(_glfw, 'glfwGetWin32Adapter'):
2863 | _glfw.glfwGetWin32Adapter.restype = ctypes.c_char_p
2864 | _glfw.glfwGetWin32Adapter.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2865 | def get_win32_adapter(monitor):
2866 | """
2867 | Returns the adapter device name of the specified monitor.
2868 |
2869 | Wrapper for:
2870 | const char* glfwGetWin32Adapter(GLFWmonitor* monitor);
2871 | """
2872 | adapter_name = _glfw.glfwGetWin32Adapter(monitor)
2873 | if adapter_name:
2874 | return adapter_name.decode('utf-8')
2875 | return None
2876 |
2877 |
2878 | if hasattr(_glfw, 'glfwGetWin32Monitor'):
2879 | _glfw.glfwGetWin32Monitor.restype = ctypes.c_char_p
2880 | _glfw.glfwGetWin32Monitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2881 | def get_win32_monitor(monitor):
2882 | """
2883 | Returns the display device name of the specified monitor.
2884 |
2885 | Wrapper for:
2886 | const char* glfwGetWin32Monitor(GLFWmonitor* monitor);
2887 | """
2888 | monitor_name = _glfw.glfwGetWin32Monitor(monitor)
2889 | if monitor_name:
2890 | return monitor_name.decode('utf-8')
2891 | return None
2892 |
2893 |
2894 | if hasattr(_glfw, 'glfwGetWin32Window'):
2895 | _glfw.glfwGetWin32Window.restype = ctypes.c_void_p
2896 | _glfw.glfwGetWin32Window.argtypes = [ctypes.POINTER(_GLFWwindow)]
2897 | def get_win32_window(window):
2898 | """
2899 | Returns the HWND of the specified window.
2900 |
2901 | Wrapper for:
2902 | HWND glfwGetWin32Window(GLFWwindow* window);
2903 | """
2904 | return _glfw.glfwGetWin32Window(window)
2905 |
2906 |
2907 | if hasattr(_glfw, 'glfwGetWGLContext'):
2908 | _glfw.glfwGetWGLContext.restype = ctypes.c_void_p
2909 | _glfw.glfwGetWGLContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
2910 | def get_wgl_context(window):
2911 | """
2912 | Returns the HGLRC of the specified window.
2913 |
2914 | Wrapper for:
2915 | HGLRC glfwGetWGLContext(GLFWwindow* window);
2916 | """
2917 | return _glfw.glfwGetWGLContext(window)
2918 |
2919 |
2920 | if hasattr(_glfw, 'glfwGetCocoaMonitor'):
2921 | _glfw.glfwGetCocoaMonitor.restype = ctypes.c_uint32
2922 | _glfw.glfwGetCocoaMonitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2923 | def get_cocoa_monitor(monitor):
2924 | """
2925 | Returns the CGDirectDisplayID of the specified monitor.
2926 |
2927 | Wrapper for:
2928 | CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor);
2929 | """
2930 | return _glfw.glfwGetCocoaMonitor(monitor)
2931 |
2932 |
2933 | if hasattr(_glfw, 'glfwGetCocoaWindow'):
2934 | _glfw.glfwGetCocoaWindow.restype = ctypes.c_void_p
2935 | _glfw.glfwGetCocoaWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
2936 | def get_cocoa_window(window):
2937 | """
2938 | Returns the NSWindow of the specified window.
2939 |
2940 | Wrapper for:
2941 | id glfwGetCocoaWindow(GLFWwindow* window);
2942 | """
2943 | return _glfw.glfwGetCocoaWindow(window)
2944 |
2945 |
2946 | if hasattr(_glfw, 'glfwGetNSGLContext'):
2947 | _glfw.glfwGetNSGLContext.restype = ctypes.c_void_p
2948 | _glfw.glfwGetNSGLContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
2949 | def get_nsgl_context(window):
2950 | """
2951 | Returns the NSOpenGLContext of the specified window.
2952 |
2953 | Wrapper for:
2954 | id glfwGetNSGLContext(GLFWwindow* window);
2955 | """
2956 | return _glfw.glfwGetNSGLContext(window)
2957 |
2958 |
2959 | if hasattr(_glfw, 'glfwGetX11Display'):
2960 | _glfw.glfwGetX11Display.restype = ctypes.c_void_p
2961 | _glfw.glfwGetX11Display.argtypes = []
2962 | def get_x11_display():
2963 | """
2964 | Returns the Display used by GLFW.
2965 |
2966 | Wrapper for:
2967 | Display* glfwGetX11Display(void);
2968 | """
2969 | return _glfw.glfwGetX11Display()
2970 |
2971 |
2972 | if hasattr(_glfw, 'glfwGetX11Adapter'):
2973 | _glfw.glfwGetX11Adapter.restype = ctypes.c_uint32
2974 | _glfw.glfwGetX11Adapter.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2975 | def get_x11_adapter(monitor):
2976 | """
2977 | Returns the RRCrtc of the specified monitor.
2978 |
2979 | Wrapper for:
2980 | RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor);
2981 | """
2982 | return _glfw.glfwGetX11Adapter(monitor)
2983 |
2984 |
2985 | if hasattr(_glfw, 'glfwGetX11Monitor'):
2986 | _glfw.glfwGetX11Monitor.restype = ctypes.c_uint32
2987 | _glfw.glfwGetX11Monitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
2988 | def get_x11_monitor(monitor):
2989 | """
2990 | Returns the RROutput of the specified monitor.
2991 |
2992 | Wrapper for:
2993 | RROutput glfwGetX11Monitor(GLFWmonitor* monitor);
2994 | """
2995 | return _glfw.glfwGetX11Monitor(monitor)
2996 |
2997 |
2998 | if hasattr(_glfw, 'glfwGetX11Window'):
2999 | _glfw.glfwGetX11Window.restype = ctypes.c_uint32
3000 | _glfw.glfwGetX11Window.argtypes = [ctypes.POINTER(_GLFWwindow)]
3001 | def get_x11_window(window):
3002 | """
3003 | Returns the Window of the specified window.
3004 |
3005 | Wrapper for:
3006 | Window glfwGetX11Window(GLFWwindow* window);
3007 | """
3008 | return _glfw.glfwGetX11Window(window)
3009 |
3010 |
3011 | if hasattr(_glfw, 'glfwSetX11SelectionString'):
3012 | _glfw.glfwSetX11SelectionString.restype = None
3013 | _glfw.glfwSetX11SelectionString.argtypes = [ctypes.c_char_p]
3014 | def set_x11_selection_string(string):
3015 | """
3016 | Sets the current primary selection to the specified string.
3017 |
3018 | Wrapper for:
3019 | void glfwSetX11SelectionString(const char* string);
3020 | """
3021 | binary_string = string.encode('utf-8')
3022 | _glfw.glfwSetX11SelectionString(binary_string)
3023 |
3024 |
3025 | if hasattr(_glfw, 'glfwGetX11SelectionString'):
3026 | _glfw.glfwGetX11SelectionString.restype = ctypes.c_char_p
3027 | _glfw.glfwGetX11SelectionString.argtypes = []
3028 | def get_x11_selection_string():
3029 | """
3030 | Returns the contents of the current primary selection as a string.
3031 |
3032 | Wrapper for:
3033 | const char* glfwGetX11SelectionString(void);
3034 | """
3035 | selection_string = _glfw.glfwGetX11SelectionString()
3036 | if selection_string:
3037 | return selection_string.decode('utf-8')
3038 | return None
3039 |
3040 |
3041 | if hasattr(_glfw, 'glfwGetGLXContext'):
3042 | _glfw.glfwGetGLXContext.restype = ctypes.c_void_p
3043 | _glfw.glfwGetGLXContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
3044 | def get_glx_context(window):
3045 | """
3046 | Returns the GLXContext of the specified window.
3047 |
3048 | Wrapper for:
3049 | GLXContext glfwGetGLXContext(GLFWwindow* window);
3050 | """
3051 | return _glfw.glfwGetGLXContext(window)
3052 |
3053 |
3054 | if hasattr(_glfw, 'glfwGetGLXWindow'):
3055 | _glfw.glfwGetGLXWindow.restype = ctypes.c_uint32
3056 | _glfw.glfwGetGLXWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
3057 | def get_glx_window(window):
3058 | """
3059 | Returns the GLXWindow of the specified window.
3060 |
3061 | Wrapper for:
3062 | GLXWindow glfwGetGLXWindow(GLFWwindow* window);
3063 | """
3064 | return _glfw.glfwGetGLXWindow(window)
3065 |
3066 |
3067 | if hasattr(_glfw, 'glfwGetWaylandDisplay'):
3068 | _glfw.glfwGetWaylandDisplay.restype = ctypes.c_void_p
3069 | _glfw.glfwGetWaylandDisplay.argtypes = []
3070 | def get_wayland_display():
3071 | """
3072 | Returns the struct wl_display* used by GLFW.
3073 |
3074 | Wrapper for:
3075 | struct wl_display* glfwGetWaylandDisplay(void);
3076 | """
3077 | return _glfw.glfwGetWaylandDisplay()
3078 |
3079 |
3080 | if hasattr(_glfw, 'glfwGetWaylandMonitor'):
3081 | _glfw.glfwGetWaylandMonitor.restype = ctypes.c_void_p
3082 | _glfw.glfwGetWaylandMonitor.argtypes = [ctypes.POINTER(_GLFWmonitor)]
3083 | def get_wayland_monitor(monitor):
3084 | """
3085 | Returns the struct wl_output* of the specified monitor.
3086 |
3087 | Wrapper for:
3088 | struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor);
3089 | """
3090 | return _glfw.glfwGetWaylandMonitor(monitor)
3091 |
3092 |
3093 | if hasattr(_glfw, 'glfwGetWaylandWindow'):
3094 | _glfw.glfwGetWaylandWindow.restype = ctypes.c_void_p
3095 | _glfw.glfwGetWaylandWindow.argtypes = [ctypes.POINTER(_GLFWwindow)]
3096 | def get_wayland_window(window):
3097 | """
3098 | Returns the main struct wl_surface* of the specified window.
3099 |
3100 | Wrapper for:
3101 | struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window);
3102 | """
3103 | return _glfw.glfwGetWaylandWindow(window)
3104 |
3105 |
3106 | if hasattr(_glfw, 'glfwGetEGLDisplay'):
3107 | _glfw.glfwGetEGLDisplay.restype = ctypes.c_void_p
3108 | _glfw.glfwGetEGLDisplay.argtypes = []
3109 | def get_egl_display():
3110 | """
3111 | Returns the EGLDisplay used by GLFW.
3112 |
3113 | Wrapper for:
3114 | EGLDisplay glfwGetEGLDisplay(void);
3115 | """
3116 | return _glfw.glfwGetEGLDisplay()
3117 |
3118 |
3119 | if hasattr(_glfw, 'glfwGetEGLContext'):
3120 | _glfw.glfwGetEGLContext.restype = ctypes.c_void_p
3121 | _glfw.glfwGetEGLContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
3122 | def get_egl_context(window):
3123 | """
3124 | Returns the EGLContext of the specified window.
3125 |
3126 | Wrapper for:
3127 | EGLContext glfwGetEGLContext(GLFWwindow* window);
3128 | """
3129 | return _glfw.glfwGetEGLContext(window)
3130 |
3131 |
3132 | if hasattr(_glfw, 'glfwGetEGLSurface'):
3133 | _glfw.glfwGetEGLSurface.restype = ctypes.c_void_p
3134 | _glfw.glfwGetEGLSurface.argtypes = [ctypes.POINTER(_GLFWwindow)]
3135 | def get_egl_surface(window):
3136 | """
3137 | Returns the EGLSurface of the specified window.
3138 |
3139 | Wrapper for:
3140 | EGLSurface glfwGetEGLSurface(GLFWwindow* window);
3141 | """
3142 | return _glfw.glfwGetEGLSurface(window)
3143 |
3144 |
3145 | if hasattr(_glfw, 'glfwGetOSMesaColorBuffer'):
3146 | _glfw.glfwGetOSMesaColorBuffer.restype = ctypes.c_int
3147 | _glfw.glfwGetOSMesaColorBuffer.argtypes = [ctypes.POINTER(_GLFWwindow), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_void_p)]
3148 | def get_os_mesa_color_buffer(window):
3149 | """
3150 | Retrieves the color buffer associated with the specified window.
3151 |
3152 | Wrapper for:
3153 | int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer);
3154 | """
3155 | width_value = ctypes.c_int(0)
3156 | width = ctypes.pointer(width_value)
3157 | height_value = ctypes.c_int(0)
3158 | height = ctypes.pointer(height_value)
3159 | format_value = ctypes.c_int(0)
3160 | format = ctypes.pointer(format_value)
3161 | buffer_value = ctypes.c_void_p(0)
3162 | buffer = ctypes.pointer(buffer_value)
3163 | success = _glfw.glfwGetOSMesaColorBuffer(window, width, height, format, buffer)
3164 | if not success:
3165 | return None
3166 | return width.value, height.value, format.value, buffer.value
3167 |
3168 |
3169 | if hasattr(_glfw, 'glfwGetOSMesaDepthBuffer'):
3170 | _glfw.glfwGetOSMesaDepthBuffer.restype = ctypes.c_int
3171 | _glfw.glfwGetOSMesaDepthBuffer.argtypes = [ctypes.POINTER(_GLFWwindow), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_void_p)]
3172 | def get_os_mesa_depth_buffer(window):
3173 | """
3174 | Retrieves the depth buffer associated with the specified window.
3175 |
3176 | Wrapper for:
3177 | int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer);
3178 | """
3179 | width_value = ctypes.c_int(0)
3180 | width = ctypes.pointer(width_value)
3181 | height_value = ctypes.c_int(0)
3182 | height = ctypes.pointer(height_value)
3183 | bytes_per_value_value = ctypes.c_int(0)
3184 | bytes_per_value = ctypes.pointer(bytes_per_value_value)
3185 | buffer_value = ctypes.c_void_p(0)
3186 | buffer = ctypes.pointer(buffer_value)
3187 | success = _glfw.glfwGetOSMesaDepthBuffer(window, width, height, bytes_per_value, buffer)
3188 | if not success:
3189 | return None
3190 | return width.value, height.value, bytes_per_value.value, buffer.value
3191 |
3192 |
3193 | if hasattr(_glfw, 'glfwGetOSMesaContext'):
3194 | _glfw.glfwGetOSMesaContext.restype = ctypes.c_void_p
3195 | _glfw.glfwGetOSMesaContext.argtypes = [ctypes.POINTER(_GLFWwindow)]
3196 | def get_os_mesa_context(window):
3197 | """
3198 | Returns the OSMesaContext of the specified window.
3199 |
3200 | Wrapper for:
3201 | OSMesaContext glfwGetOSMesaContext(GLFWwindow* window);
3202 | """
3203 | return _glfw.glfwGetOSMesaContext(window)
3204 |
3205 | if hasattr(_glfw, 'glfwInitAllocator'):
3206 | _allocate_callback = None
3207 | _reallocate_callback = None
3208 | _deallocate_callback = None
3209 | _glfw.glfwInitAllocator.restype = None
3210 | _glfw.glfwInitAllocator.argtypes = [ctypes.POINTER(_GLFWallocator)]
3211 | def init_allocator(allocate, reallocate, deallocate):
3212 | """
3213 | Sets the init allocator to the desired value.
3214 |
3215 | Wrapper for:
3216 | void glfwInitAllocator(const GLFWallocator* allocator);
3217 | """
3218 | global _allocate_callback
3219 | global _reallocate_callback
3220 | global _deallocate_callback
3221 | if allocate is None and reallocate is None and deallocate is None:
3222 | allocator_ptr = ctypes.POINTER(_GLFWallocator)(0)
3223 | else:
3224 | if allocate is None:
3225 | allocate = 0
3226 | c_allocate = _GLFWallocatefun(allocate)
3227 | _allocate_callback = (allocate, c_allocate)
3228 | if reallocate is None:
3229 | reallocate = 0
3230 | c_reallocate = _GLFWreallocatefun(reallocate)
3231 | _reallocate_callback = (reallocate, c_reallocate)
3232 | if deallocate is None:
3233 | deallocate = 0
3234 | c_deallocate = _GLFWdeallocatefun(deallocate)
3235 | _deallocate_callback = (deallocate, c_deallocate)
3236 | allocator = _GLFWallocator()
3237 | allocator.allocate = c_allocate
3238 | allocator.reallocate = c_reallocate
3239 | allocator.deallocate = c_deallocate
3240 | allocator_ptr = ctypes.byref(allocator)
3241 | _glfw.glfwInitAllocator(allocator_ptr)
3242 |
3243 | if hasattr(_glfw, 'glfwInitVulkanLoader'):
3244 | _loader_callback = None
3245 | _loader_callback_type = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p)
3246 | _glfw.glfwInitVulkanLoader.restype = None
3247 | _glfw.glfwInitVulkanLoader.argtypes = [_loader_callback_type]
3248 | def init_vulkan_loader(loader):
3249 | """
3250 | Sets the desired Vulkan `vkGetInstanceProcAddr` function.
3251 |
3252 | Wrapper for:
3253 | void glfwInitVulkanLoader(PFN_vkGetInstanceProcAddr loader);
3254 | """
3255 | global _loader_callback
3256 | if loader is None:
3257 | loader = 0
3258 | c_loader = _loader_callback_type(loader)
3259 | _loader_callback = (loader, c_loader)
3260 | _glfw.glfwInitVulkanLoader(c_loader)
3261 |
3262 | if hasattr(_glfw, 'glfwGetPlatform'):
3263 | _glfw.glfwGetPlatform.restype = ctypes.c_int
3264 | _glfw.glfwGetPlatform.argtypes = []
3265 | def get_platform():
3266 | """
3267 | Returns the currently selected platform.
3268 |
3269 | Wrapper for:
3270 | int glfwGetPlatform(void);
3271 | """
3272 | return _glfw.glfwGetPlatform()
3273 |
3274 | if hasattr(_glfw, 'glfwPlatformSupported'):
3275 | _glfw.glfwPlatformSupported.restype = ctypes.c_int
3276 | _glfw.glfwPlatformSupported.argtypes = [ctypes.c_int]
3277 | def platform_supported(platform):
3278 | """
3279 | Returns whether the library includes support for the specified platform.
3280 |
3281 | Wrapper for:
3282 | int glfwPlatformSupported(int platform);
3283 | """
3284 | return _glfw.glfwPlatformSupported(platform)
3285 |
3286 | if hasattr(_glfw, 'glfwGetWindowTitle'):
3287 | _glfw.glfwGetWindowTitle.restype = ctypes.c_char_p
3288 | _glfw.glfwGetWindowTitle.argtypes = [ctypes.POINTER(_GLFWwindow)]
3289 | def get_window_title(window):
3290 | """
3291 | Returns the title of the specified window.
3292 |
3293 | Wrapper for:
3294 | const char* glfwGetWindowTitle(GLFWwindow* window);
3295 | """
3296 | window_title = _glfw.glfwGetWindowTitle(window)
3297 | if window_title:
3298 | return window_title.decode('utf-8')
3299 | return None
3300 |
3301 |
3302 | _prepare_errcheck()
3303 |
--------------------------------------------------------------------------------
/glfw/library.py:
--------------------------------------------------------------------------------
1 | """
2 | Python bindings for GLFW.
3 | """
4 |
5 | from __future__ import print_function
6 | from __future__ import division
7 | from __future__ import unicode_literals
8 |
9 | import ctypes
10 | import os
11 | import glob
12 | import sys
13 | import subprocess
14 | import textwrap
15 |
16 |
17 | def _find_library_candidates(library_names,
18 | library_file_extensions,
19 | library_search_paths):
20 | """
21 | Finds and returns filenames which might be the library you are looking for.
22 | """
23 | candidates = []
24 | for search_path in library_search_paths:
25 | if not search_path:
26 | continue
27 | for library_name in library_names:
28 | glob_query = os.path.join(search_path, '*'+library_name+'.*')
29 | for filename in glob.iglob(glob_query):
30 | filename = os.path.realpath(filename)
31 | if filename in candidates:
32 | continue
33 | basename = os.path.basename(filename)
34 | if basename.startswith('lib'+library_name):
35 | basename_end = basename[len('lib'+library_name):]
36 | elif basename.startswith(library_name):
37 | basename_end = basename[len(library_name):]
38 | else:
39 | continue
40 | for file_extension in library_file_extensions:
41 | if basename_end.startswith(file_extension):
42 | if basename_end[len(file_extension):][:1] in ('', '.'):
43 | candidates.append(filename)
44 | elif basename_end.endswith(file_extension):
45 | basename_middle = basename_end[:-len(file_extension)]
46 | if all(c in '0123456789.' for c in basename_middle):
47 | candidates.append(filename)
48 | return candidates
49 |
50 |
51 | def _load_library(library_names, library_file_extensions,
52 | library_search_paths, version_check_callback):
53 | """
54 | Finds, loads and returns the most recent version of the library.
55 | """
56 | candidates = _find_library_candidates(library_names,
57 | library_file_extensions,
58 | library_search_paths)
59 | library_versions = []
60 | for filename in set(candidates):
61 | version = version_check_callback(filename)
62 | if version is not None and version >= (3, 0, 0):
63 | library_versions.append((version, filename))
64 |
65 | if not library_versions:
66 | return None
67 | library_versions.sort()
68 | return ctypes.CDLL(library_versions[-1][1])
69 |
70 |
71 | def _load_first_library(library_names, library_file_extensions,
72 | library_search_paths):
73 | """
74 | Finds, loads and returns the first found version of the library.
75 | """
76 | candidates = _find_library_candidates(
77 | library_names,
78 | library_file_extensions,
79 | library_search_paths
80 | )
81 | library = None
82 | for filename in candidates:
83 | if os.path.isfile(filename):
84 | try:
85 | library = ctypes.CDLL(filename)
86 | break
87 | except OSError:
88 | pass
89 | if library is not None:
90 | major_value = ctypes.c_int(0)
91 | major = ctypes.pointer(major_value)
92 | minor_value = ctypes.c_int(0)
93 | minor = ctypes.pointer(minor_value)
94 | rev_value = ctypes.c_int(0)
95 | rev = ctypes.pointer(rev_value)
96 | if hasattr(library, 'glfwGetVersion'):
97 | library.glfwGetVersion(major, minor, rev)
98 | version = (major_value.value, minor_value.value, rev_value.value)
99 | if version >= (3, 0, 0):
100 | return library
101 | return None
102 |
103 |
104 | def _glfw_get_version(filename):
105 | """
106 | Queries and returns the library version tuple or None by using a
107 | subprocess.
108 | """
109 | version_checker_source = '''
110 | import sys
111 | import ctypes
112 |
113 | def get_version(library_handle):
114 | """
115 | Queries and returns the library version tuple or None.
116 | """
117 | major_value = ctypes.c_int(0)
118 | major = ctypes.pointer(major_value)
119 | minor_value = ctypes.c_int(0)
120 | minor = ctypes.pointer(minor_value)
121 | rev_value = ctypes.c_int(0)
122 | rev = ctypes.pointer(rev_value)
123 | if hasattr(library_handle, 'glfwGetVersion'):
124 | library_handle.glfwGetVersion(major, minor, rev)
125 | version = (major_value.value,
126 | minor_value.value,
127 | rev_value.value)
128 | return version
129 | else:
130 | return None
131 |
132 | if sys.version_info[0] == 2:
133 | input_func = raw_input
134 | else:
135 | input_func = input
136 | filename = input_func().strip()
137 |
138 | try:
139 | library_handle = ctypes.CDLL(filename)
140 | except OSError:
141 | pass
142 | else:
143 | version = get_version(library_handle)
144 | print(version)
145 | '''
146 |
147 | args = [sys.executable, '-c', textwrap.dedent(version_checker_source)]
148 | process = subprocess.Popen(args, universal_newlines=True,
149 | stdin=subprocess.PIPE, stdout=subprocess.PIPE)
150 | out = process.communicate(filename)[0]
151 | out = out.strip()
152 | if out:
153 | return eval(out)
154 | else:
155 | return None
156 |
157 |
158 | def _get_library_search_paths():
159 | """
160 | Returns a list of library search paths, considering of the current working
161 | directory, default paths and paths from environment variables.
162 | """
163 | package_path = os.path.abspath(os.path.dirname(__file__))
164 | search_paths = [
165 | '',
166 | package_path,
167 | sys.prefix + '/lib',
168 | '/usr/lib64',
169 | '/usr/local/lib64',
170 | '/usr/lib', '/usr/local/lib',
171 | '/opt/homebrew/lib',
172 | '/run/current-system/sw/lib',
173 | '/usr/lib/x86_64-linux-gnu/',
174 | '/usr/lib/aarch64-linux-gnu/',
175 | '/usr/lib/arm-linux-gnueabihf',
176 | '/usr/lib/riscv64-linux-gnu',
177 | '/usr/lib/powerpc64le-linux-gnu',
178 | '/usr/lib/loongarch64-linux-gnu',
179 | '/usr/lib/s390x-linux-gnu',
180 | '/usr/lib/i386-linux-gnu',
181 | '/usr/lib/arm-linux-gnueabi',
182 | '/usr/lib/sparc64-linux-gnu',
183 | '/usr/lib/mips64el-linux-gnuabi64',
184 | ]
185 |
186 | package_path_variant = _get_package_path_variant(package_path)
187 | if package_path_variant:
188 | search_paths.insert(1, package_path_variant)
189 |
190 | if sys.platform == 'darwin':
191 | path_environment_variable = 'DYLD_LIBRARY_PATH'
192 | else:
193 | path_environment_variable = 'LD_LIBRARY_PATH'
194 | if path_environment_variable in os.environ:
195 | search_paths.extend(os.environ[path_environment_variable].split(':'))
196 | return search_paths
197 |
198 |
199 | def _get_frozen_library_search_paths():
200 | """
201 | Returns a list of library search paths for frozen executables.
202 | """
203 | current_path = os.path.abspath(os.getcwd())
204 | executable_path = os.path.abspath(os.path.dirname(sys.executable))
205 | package_path = os.path.abspath(os.path.dirname(__file__))
206 | package_path_variant = _get_package_path_variant(package_path)
207 | return [
208 | executable_path,
209 | package_path_variant,
210 | package_path,
211 | current_path
212 | ]
213 |
214 |
215 | def _get_package_path_variant(package_path):
216 | if sys.platform in ('darwin', 'win32'):
217 | return None
218 | # manylinux2014 wheels contain libraries built for X11 and Wayland
219 | if os.environ.get('PYGLFW_LIBRARY_VARIANT', '').lower() in ['wayland', 'x11']:
220 | return os.path.join(package_path, os.environ['PYGLFW_LIBRARY_VARIANT'].lower())
221 | elif os.environ.get('XDG_SESSION_TYPE') == 'wayland':
222 | return os.path.join(package_path, 'wayland')
223 | else:
224 | # X11 is the default, even if XDG_SESSION_TYPE is not set
225 | return os.path.join(package_path, 'x11')
226 |
227 |
228 | if os.environ.get('PYGLFW_LIBRARY', ''):
229 | try:
230 | glfw = ctypes.CDLL(os.environ['PYGLFW_LIBRARY'])
231 | except OSError:
232 | glfw = None
233 | elif sys.platform == 'win32':
234 | glfw = None # Will become `not None` on success.
235 |
236 | # try Windows default search path
237 | try:
238 | glfw = ctypes.CDLL('glfw3.dll')
239 | except OSError:
240 | pass
241 |
242 | # try package directory
243 | if glfw is None:
244 | try:
245 | # load Microsoft Visual C++ 2013 runtime
246 | msvcr = ctypes.CDLL(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'msvcr120.dll'))
247 | glfw = ctypes.CDLL(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'glfw3.dll'))
248 | except OSError:
249 | pass
250 |
251 | # try conda's default location on Windows
252 | if glfw is None:
253 | try:
254 | glfw = ctypes.CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'glfw3.dll'))
255 | except OSError:
256 | pass
257 | elif not getattr(sys, "frozen", False):
258 | glfw = _load_library(['glfw', 'glfw3'], ['.so', '.dylib'],
259 | _get_library_search_paths(), _glfw_get_version)
260 | else:
261 |
262 | glfw = _load_first_library(['glfw', 'glfw3'], ['.so', '.dylib'],
263 | _get_frozen_library_search_paths())
264 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup
2 | import os.path
3 |
4 | setup_directory = os.path.abspath(os.path.dirname(__file__))
5 |
6 | with open(os.path.join(setup_directory, 'README.rst')) as readme_file:
7 | long_description = readme_file.read()
8 |
9 | setup(
10 | name='glfw',
11 | version='2.9.0',
12 | description='A ctypes-based wrapper for GLFW3.',
13 | long_description=long_description,
14 | url='https://github.com/FlorianRhiem/pyGLFW',
15 | author='Florian Rhiem',
16 | author_email='florian.rhiem@gmail.com',
17 | license='MIT',
18 | classifiers=[
19 | 'Development Status :: 5 - Production/Stable',
20 | 'Environment :: MacOS X',
21 | 'Environment :: X11 Applications',
22 | 'Intended Audience :: Developers',
23 | 'License :: OSI Approved :: MIT License',
24 | 'Programming Language :: Python :: 2',
25 | 'Programming Language :: Python :: 3',
26 | 'Topic :: Multimedia :: Graphics',
27 | 'Topic :: Scientific/Engineering :: Visualization',
28 | ],
29 | packages=['glfw'],
30 | package_data={
31 | # include GLFW shared library and Visual C++ runtimes in wheel package
32 | 'glfw': [
33 | 'glfw3.dll',
34 | 'libglfw.3.dylib',
35 | 'wayland/libglfw.so',
36 | 'x11/libglfw.so',
37 | 'libglfw.so',
38 | 'msvcr120.dll',
39 | ]
40 | },
41 | extras_require={
42 | 'preview': ['glfw_preview']
43 | }
44 | )
45 |
--------------------------------------------------------------------------------
/utils/glfw_preview/README.md:
--------------------------------------------------------------------------------
1 | # glfw_preview
2 |
3 | This is a helper package for the glfw package that enables wrappers for unreleased GLFW3 macros and functions.
--------------------------------------------------------------------------------
/utils/glfw_preview/glfw_preview/__init__.py:
--------------------------------------------------------------------------------
1 | """
2 | This is a helper package for the glfw package that enables wrappers for unreleased GLFW3 macros and functions.
3 | """
4 |
--------------------------------------------------------------------------------
/utils/glfw_preview/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup
2 |
3 | setup(
4 | name='glfw_preview',
5 | version='0.0.3',
6 | description='A helper package for the glfw package.',
7 | long_description='This is a helper package for the glfw package that enables wrappers for unreleased GLFW3 macros and functions.',
8 | url='https://github.com/FlorianRhiem/pyGLFW',
9 | author='Florian Rhiem',
10 | author_email='florian.rhiem@gmail.com',
11 | license='MIT',
12 | classifiers=[
13 | 'Development Status :: 5 - Production/Stable',
14 | 'Environment :: MacOS X',
15 | 'Environment :: X11 Applications',
16 | 'Intended Audience :: Developers',
17 | 'License :: OSI Approved :: MIT License',
18 | 'Programming Language :: Python :: 2',
19 | 'Programming Language :: Python :: 3',
20 | 'Topic :: Multimedia :: Graphics',
21 | 'Topic :: Scientific/Engineering :: Visualization',
22 | ],
23 | packages=['glfw_preview'],
24 | )
25 |
--------------------------------------------------------------------------------
/vcredist/msvcr120.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FlorianRhiem/pyGLFW/4ecaed5a7313fc1eeaefc15eb381117d15ea44b3/vcredist/msvcr120.dll
--------------------------------------------------------------------------------