OpenGL Mathematics library for Python
Project description
PyGLM
OpenGL Mathematics (GLM) library for Python
GLSL + Optional features + Python = PyGLM
A mathematics library for graphics programming.
PyGLM is a Python extension written in C++.
By using GLM by G-Truc under the hood, it manages to bring glm's features to Python.
Some features are unsupported (such as unstable extensions) - Please see [Unsupported Functions] below.
If you encounter any issues or want to request a feature, please create an issue on the issue tracker.
Tiny Documentation
Why PyGLM?
Besides the obvious - being mostly compatible with GLM - PyGLM offers a variety of features for vector and matrix manipulation.
It has a lot of possible use cases, including 3D-Graphics (OpenGL, DirectX, ...), Physics and more.
At the same time, it has great performance, being between 2x and 15x as fast as numpy! (see end of page)
(depending on the individual function)
Installation
PyGLM supports Windows, Linux, MacOS and other operating systems with either x86 (32-bit) or x64 (64-bit) architecture,
running Python 3.5 or higher. (Prior versions of Python - such as Python 2 - were supported up to PyGLM version 0.4.8b1)
It can be installed from the PyPI using pip:
pip install pyglm
And finally imported and used:
import glm
Using PyGLM
PyGLM's syntax is very similar to the original GLM's syntax.
There is no need to import anything but glm, as it already contains the entire package.
License requirements
Please make sure to include the license for GLM in your project when you use PyGLM!
(this also includes binary distributions, e.g. *.exe)
You can do so by copying the COPYING
file (or it's contents) to your project.
Differences to glm
Instead of using double colons (::) for namespaces, periods (.) are used, so
glm::vec2
becomes glm.vec2
.
PyGLM supports the buffer protocol, meaning its compitible to other objects that support the buffer protocol,
such as bytes
or numpy.array
(for example you can convert a glm matrix to a numpy array and vice versa).
PyGLM is also capable of interpreting iterables (such as tuples) as vectors, so e.g. the following equasion is possible:
result = glm.vec2(1) * (2, 3)
PyGLM doesn't support precision qualifiers. All types use the default precision (packed_highp
).
If a glm function normally accepts float
and double
arguments, the higher precision (double
) is used.
There is no way to set preprocessor definitions (macros).
If - for example - you need to use the left handed coordinate system, you have to use *LH, so
glm.perspective
becomes glm.perspectiveLH
.
All types are initialized by default to avoid memory access violations.
(i.e. the macro GLM_FORCE_CTOR_INIT
is defined)
In case you need the size of a PyGLM datatype, you can use
glm.sizeof(<type>)
The function glm.identity
requires a matrix type as it's argument.
The function glm.frexp(x, exp)
returns a tuple (m, e)
, if the input arguments are numerical.
This function may issue a UserWarning
. You can silence this warning using glm.silence(1)
.
The function glm.value_ptr(x)
returns a ctypes pointer of the respective type.
I.e. if the datatype of x
is float
, then a c_float
pointer will be returned.
Likewise the reverse-functions (such as make_vec2(ptr)
) will take a ctypes pointer as their argument
and return (in this case) a 2 component vector of the pointers underlying type.
glm.silence(ID)
can be used to silence specific warnings.
Supplying an id of 0 will silence all warnings.
There is currently no documentation for PyGLM.
Please refer to the source (in Python: *.__doc__) and GLM manuals, references and tutorials.
Unsupported functions
Aside from the unstable extensions,
PyGLM doesn't support the following extensions and methods, due to compatability issues:
The GLM_GTC_bitfield
extension,
glm::log2
from GLM_GTC_integer.
glm::packUnorm
and glm::packSnorm
from GLM_GTC_packing.
Build options
PyGLM can be built from source in a couple of different ways.
In build_options.h
there is a preprocessor option PyGLM_BUILD
which is set to PyGLM_DEFAULT
by default.
PyGLM_DEFAULT
will build all of PyGLM's functions and features.
A few other flags exist:
PyGLM_FAST
removes PyGLM's iterable and GetBuffer checking, thus making it incompatible with tuples, numpy arrays and bytes objects while increasing overall performance.
PyGLM_NO_FUNCTIONS
removes all of the functions of glm and only builds the bare types.
PyGLM_MINIMAL
combines PyGLM_FAST
and PyGLM_NO_FUNCTIONS
.
Example
>>> import glm
>>> v = glm.vec3()
>>> v.x = 7
>>> print(v.xxy)
vec3( 7, 7, 0 )
>>> m = glm.mat4()
>>> print(m)
[ 1 | 0 | 0 | 0 ]
[ 0 | 1 | 0 | 0 ]
[ 0 | 0 | 1 | 0 ]
[ 0 | 0 | 0 | 1 ]
>>> v = glm.vec4(1, 2, 3, 4)
>>> print(v + (8, 7, 6, 5))
vec4( 9, 9, 9, 9 )
Speed comparison to numpy
How PyGLM's performance roughly compares to NumPy's performance:
instruction | np speed (%) | glm speed (%)
import | 4.76 | 100.00
mat4() | 9.76 | 100.00
dot(vec3, vec3) | 28.92 | 100.00
transpose(mat4) | 25.64 | 100.00
vec4 * vec4 | 27.89 | 100.00
mat4 * vec4 | 17.68 | 100.00
mat4[0] | 49.99 | 100.00
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file PyGLM-1.2.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 973.4 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ae87962c5689b84810506ebcfbf20b74b99849a182836c7ce8df65cb8af6ff |
|
MD5 | 2d07c9dfea7d811a629caea07030d0db |
|
BLAKE2b-256 | 37c5e8c5901b716d46e072e9241b76f29d48f4388ee54803bb7f87eb37df27e2 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp38-cp38-win32.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp38-cp38-win32.whl
- Upload date:
- Size: 810.4 kB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6638a3b9e1bca272647b21784e70fb2306f85da74bb40ba1832e32b1c3171c05 |
|
MD5 | b9bfd9f019a06fa3ef29ff4fe08c1633 |
|
BLAKE2b-256 | cedb0e93264c52bc0f5f16626db6d80b973a6f3645633854635c507a831133c4 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 5.7 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e789f9fffc1a2e607984e0883d080b3ee136ef4e5cd18d1c0f9b89701afabe2 |
|
MD5 | 523b1e75d468e6cb0f25153a900beb79 |
|
BLAKE2b-256 | 506b6b416551e1cf92b5fdb2b5ec6de7e3e441d5f73804a0f2179f3aad4ac2d5 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp38-cp38-manylinux1_i686.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp38-cp38-manylinux1_i686.whl
- Upload date:
- Size: 5.0 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a5bd99c9cfa1561265ef737b950427585c98c9d2e9c3cf3c8191d9f4eb04b56 |
|
MD5 | 25f4991853088b14b2a3fd7dc879c742 |
|
BLAKE2b-256 | 8350f278cde824739199b9a2fece040a150bc8d18f6d18239b484f17c666c8a9 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 942f65291535cdb4787d6c80f7f6887ecd28c58c12d2dc5cf1241e409ba32fa9 |
|
MD5 | 04c8ed464ca91120ba4c911fbe53be2f |
|
BLAKE2b-256 | 4819edb9e78fa13b4febd3237c251265a10ccd443bbef7f1a3b1b01374072d88 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 968.6 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08f5246200d9692431f80d599ee893d209bca4b6b9cdd974817c08c89743aea8 |
|
MD5 | 5239e59fbdd283d6488f3b8524851cc6 |
|
BLAKE2b-256 | a78e2f2522b3cbf252261e02509ab597a1422b26bcbad078518f51331e0a1c35 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp37-cp37m-win32.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp37-cp37m-win32.whl
- Upload date:
- Size: 807.9 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c2c326a7b24c05dab4cbf000ceed1004d12b18fcb08974a649d8d677db8f9b7 |
|
MD5 | 41569dbd3b627a3a24b07f0a3b6da57f |
|
BLAKE2b-256 | 9fd9d84fec2ea5e14f4c1af85e9fe461a3954d959ee6f03cd8f7a09b731c96e2 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.6 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f698673a49c0ca143d3fa827a641974f92b41b6196af70ac6e3ca0b23bb3c8ac |
|
MD5 | 34d343ea55e7fbdb0853da60248ed13e |
|
BLAKE2b-256 | 4d1dff17513dc5aefdabcbcd7564ff9af2dab488a6d30bcce3a87f58ce729e8e |
Provenance
File details
Details for the file PyGLM-1.2.0-cp37-cp37m-manylinux1_i686.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp37-cp37m-manylinux1_i686.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14743bd34fd3d91c5680d40ebfa2c640adcfd2d54b4f892d225525c0675f5893 |
|
MD5 | e62e6717026cc959ca71dfaa5bf3d6a6 |
|
BLAKE2b-256 | a7bd81a286148957e89f46eb9d561f363b3577cadcd86972208fcc8219859c47 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp37-cp37m-macosx_10_9_intel.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp37-cp37m-macosx_10_9_intel.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.7m, macOS 10.9+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84e8ab055b568655b8977708232d71e1760bd9f1cda1bad449e5ee880ea6c589 |
|
MD5 | ce53a4322467e1c76455e2fee7f26896 |
|
BLAKE2b-256 | 59bf5b0f118a7228141ffda853e03f1b8b53c18ae1f20c5ba0778b9af69cb820 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 968.6 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e67dd8fd9b10cdd8fd32c256726c8e5c14bb62ea94fd9319a4d695adf0623bb |
|
MD5 | 398f5da5ab29b4224d2b1732524b849d |
|
BLAKE2b-256 | f9318f63ffd4ff46a2d8ce638f289a99bb6f3990211105ce2558681209a4cf37 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp36-cp36m-win32.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp36-cp36m-win32.whl
- Upload date:
- Size: 807.9 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 880632511ff8483ff87b70c415c174e92ab8cf78901e6d274299442983ca3e44 |
|
MD5 | c258ef269b619fd344bde366d4c82198 |
|
BLAKE2b-256 | 5bacf68812e4c47b24ff07c760183b9057999e30b21d334b01da5614d11aef72 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.6 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 045b07fd3866a5ad5dcf8844fb2770362a6b60538324ae95f0fd454614bef665 |
|
MD5 | 078968c94ea58dea00e2c77e550da29c |
|
BLAKE2b-256 | 7758f2a66724ebe4f1d79d84c8914d54759c7d1f0f01c57795c83f053e0b81e4 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44c8455dd6b51a92ba5cb6358fb046176e01978492153e1e14d5ff1202c04078 |
|
MD5 | 3220d7eb127c1d823eb5e45672da8104 |
|
BLAKE2b-256 | e46c26146d1eafe777399dbd7d5f6c46846c32ff3ec0db64e0c6c8cf780127db |
Provenance
File details
Details for the file PyGLM-1.2.0-cp36-cp36m-macosx_10_9_intel.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp36-cp36m-macosx_10_9_intel.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.6m, macOS 10.9+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 727ee3d45b9e12aa439ef10abd06302480f7ed2b0456350d7daa153f98fa6876 |
|
MD5 | a8df74f878799e953a3cf31e57163dad |
|
BLAKE2b-256 | e09c70482aa92aed735bc839b75504fd804b96c0e7a9afda15e3c87984c638e1 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 968.6 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f916e4314709136ad257e612888692b63dee880c0786550315a867c7a18703fd |
|
MD5 | 6082227d1b0fbbf5ce7c1921a11be2d1 |
|
BLAKE2b-256 | cb7c8e322e2ddde0eed946763488957b8e11098efa271e389f0e379150dcb978 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp35-cp35m-win32.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp35-cp35m-win32.whl
- Upload date:
- Size: 807.9 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf92b9d0524233431c6a1341fe3375afa8e4caf0edc61ee62d8b7dc66b9d5a9c |
|
MD5 | c2a3fbbac158537504046513c3b0d7f1 |
|
BLAKE2b-256 | 3ea78cb483fe30a5ffe91960c4f1145fe8d3723ca3c32149a7ab2200dc2b6021 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.6 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ad3cf3245a47b5baede07e89da573699412fcaf0ea7500174208d919d58f4a0 |
|
MD5 | 94972688211040f1870dd9fd37340b89 |
|
BLAKE2b-256 | bb9c475522021b3ea8998aa3b34c186e34d2981db1f5b6506fb636005db1cc16 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b43efc489d6195c01979b9eb517650f4460f53665bc57872eb42b08613fd03a5 |
|
MD5 | 4a112135b03a0a2e8cc69327dfc33414 |
|
BLAKE2b-256 | aebac34673caf2dbceac399b6f6c50ad568c71f08a9b4ac11ca96a568e3bb9d1 |
Provenance
File details
Details for the file PyGLM-1.2.0-cp35-cp35m-macosx_10_9_intel.whl
.
File metadata
- Download URL: PyGLM-1.2.0-cp35-cp35m-macosx_10_9_intel.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.5m, macOS 10.9+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bcdbd6570a7945f995bbac8c80abec2fd3e8d208b798233bb95244de3d00998 |
|
MD5 | 121ae9cf7bc5b54e23190316073dfb24 |
|
BLAKE2b-256 | 29b90f46181ed6fa4093e7bf0ef993ce895e47fcc8ba618401778e854b6a4b07 |