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 most 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.
For a (barely) complete reference, please take a look at the wiki.
Tiny Documentation
FAQ
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
# please make sure to install "PyGLM" and not "glm", which is a different module
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)
Note: This feature might not or only partially be available in PyGLM versions prior to 2.0.0
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.
Unsupported functions
Aside from most of 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.
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 Distribution
Built Distributions
Hashes for PyGLM-1.99.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc06caa2eaeaf60cbd23ac67794d302ba9db73a053a409f475a8874b2e74eb34 |
|
MD5 | b38057ebbf965bc3dd83f10823db90c9 |
|
BLAKE2b-256 | e82bb4c53455ba33724a6c98b3307b7040e8350b209bc1769df26901c90f5d18 |
Hashes for PyGLM-1.99.3-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2e8e72549ad4d487f295e0c6dda2f4a2ab5405d7061f62cbf6f1aa1bab0a5b5 |
|
MD5 | 354525e9a91e66a3e17c8c3b1a5bba5a |
|
BLAKE2b-256 | 0daa20f8e1046676f1aa2680a5dd56d9cbd2b4d350162c526e1e7a9a80e04e18 |
Hashes for PyGLM-1.99.3-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 013a753e7f543d22ba5b615283496a6e158676722d5448d4e9098e9f3d7aac09 |
|
MD5 | 6f03e18760de835665683b55e4fd813f |
|
BLAKE2b-256 | 082816b4cbf0cbacc7bac136b113b691190b8a91f1dcabe7924217b07b112435 |
Hashes for PyGLM-1.99.3-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aae7abf027f93c90a5ba6d6c9bb1f1a8ff378aa8ec7ee2edd8301f4c641c24a1 |
|
MD5 | 534093fa00219d232ba918dc1c5a55ed |
|
BLAKE2b-256 | 938932c090c03611873afd61227fc6333a1ae675ee7fcc5bdc4005b352ed9a5e |
Hashes for PyGLM-1.99.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 432ff23642080e1cfa3b03c493aa9060363f7188a46cebba47c0f08bb99317ab |
|
MD5 | 31d42821c963e5e53b5b872ea08c3a1b |
|
BLAKE2b-256 | b9a9d3720487e823aa01dae420885e5c5538e675e2187ee77e0c6fec294ae7f7 |
Hashes for PyGLM-1.99.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09e8dd6cd6528509a8f3be6c0af849f69512272a2ca3898381ce03e13ccaa691 |
|
MD5 | 2ca614e3dcb9a5422a3ffad0fd77b6f6 |
|
BLAKE2b-256 | 5ad69e5710da3a5d7c634eb5e67fbca335a91e04103c2b6d982c29e208ecb956 |
Hashes for PyGLM-1.99.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e16f3f5288ae23163e8820622213930cf914eda6beb714b4ec1368a62b78534 |
|
MD5 | df2778b3a535fadff948cfb2e0208531 |
|
BLAKE2b-256 | 7e2c9f7b7747406afbdffe5eff695c5e2bed0c656dee30250fd011e4418e54dc |
Hashes for PyGLM-1.99.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ead6863305f2dc0d7114fb5dbee9b1906d595f3c825f72dca1d5087c48358db8 |
|
MD5 | e13d9977c3caab5d817cc5484d180f89 |
|
BLAKE2b-256 | 0ee9a74c3f55e8fb50eeda59486237b56573b06536697b9a7b835bcb5a8f15ae |
Hashes for PyGLM-1.99.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39ff78d5a2be498f8f93dbdeaad140000451b3b53778967663b0d69138fb3e2c |
|
MD5 | 6bc05bca70552cb4d7a2f2ae32aebeae |
|
BLAKE2b-256 | 201cb417092634f99f79b72cad6461d3fc508db506a65f1b18f04ba278c724f4 |
Hashes for PyGLM-1.99.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f9164ccb9db0f8a5ad525892094fc88f9ae2e5408974e2b1fe48348f19cadd1 |
|
MD5 | 9606d65648f6e808ad802f89244b704a |
|
BLAKE2b-256 | f452e5fb93648aef8c0e93e42b464d255dd475ea4a1467b5341a216a966f9c33 |
Hashes for PyGLM-1.99.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e70237bf048df44e598df710c77f5da1707c44fd9c34f6424ad6ed7b80114980 |
|
MD5 | ea6fda68374cbe40d4ef605ffeecb036 |
|
BLAKE2b-256 | 17ddbe3fa274f7a7692266e2ff2455123876f7a776ea65ed1dc8985aad1fbabd |
Hashes for PyGLM-1.99.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6211033574487202ddfd78a5d2bd2583d463f037b653388058f440f954df02cd |
|
MD5 | e1f346839b2de02239fd1d21d8f360f5 |
|
BLAKE2b-256 | 35fd50b030a5a8527c8f8f2fdacedf86e6b16a45415c28dd4be7039ee0d0d721 |
Hashes for PyGLM-1.99.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | baaa16cc18dc7ce985ccf2582e99c1319a20d2da611640de8eadc61616e4a5b2 |
|
MD5 | 172c60713ed580cadd83a1b3a67c3b5d |
|
BLAKE2b-256 | f5551e75ebb1546853fb321b841292bdc31896c9286fbe4bcc118ea0e923f959 |
Hashes for PyGLM-1.99.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bb989100778fca7d518ea1d779ac516c39cfe0ead9d0fede4d7f1d5b879ebb5 |
|
MD5 | ca785cd7f9d026bdd75b147034924c13 |
|
BLAKE2b-256 | fd30e6bc2e7d86dae539604c1c638e21c86348d78227005bd9b756f5fa34ec0f |
Hashes for PyGLM-1.99.3-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cfe4225415e4b4e81acb7e4b3ec7600a677ee0032a229eec739d40d3a68c8b3 |
|
MD5 | 18323e329533e190783e1f414c5e9ba8 |
|
BLAKE2b-256 | 7c39d10d72fb26a19f100da78365886eee8731fb8ff1337cdecb9c8cbe13b656 |
Hashes for PyGLM-1.99.3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50947578c1be107bf0e3bbdf28261a9acb91fb5af48a7a6c4765f2619521c178 |
|
MD5 | 67f516b31e6913db3d9aab6afe034754 |
|
BLAKE2b-256 | a37d73a7f2a1b142727409e408462b9c2137c68ac36f0058cffbf7f0e787883b |
Hashes for PyGLM-1.99.3-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67366c6f1e0b41bf6ad0ba9ef18563986759f000e7d436877a1698c8ca444e97 |
|
MD5 | 6c058cc307cac1e802f5bdab8b623640 |
|
BLAKE2b-256 | 548898ab177faf4ec14e0003eef0f2fb0aef5841548a310d582dad57e0600e9b |
Hashes for PyGLM-1.99.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cec8e9882915c98d587f91a6b9b76ff4c686039eae23bf30ad21ad1912b4395a |
|
MD5 | 10919924963f9f6348dec3999a9a696f |
|
BLAKE2b-256 | 91a6b0901f0f9f3416e13510a974b88ee74628b14cc1fbdee53a809e274c752e |
Hashes for PyGLM-1.99.3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa1713500f4af4ab9ca448bea0b84be2f813e3345c95d8c265d41c8f8b2d7138 |
|
MD5 | 7f1e8b24cfd6e4e0c664008b9230254e |
|
BLAKE2b-256 | 2fae906cd31d4292f06687868d485a539389e22169aa9638b67aebd2fb464d21 |
Hashes for PyGLM-1.99.3-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edd4f1ca2d5b40eada0b868e181aee7f779307ebf6ce6a187d8fea6914fd5cae |
|
MD5 | f93718dedd7f3dc29b47ac13d762c989 |
|
BLAKE2b-256 | fb5de1e16c4471f7aca4aa23c025285c8751b4adae03ac0b61e3e491c24ea3fe |