Skip to main content

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 either the COPYING or GLM_LICENSE file (or their 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 compatibility 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 PyGLM.cpp 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

Metadata

Release files for pyglm 1.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyglm 1.1.5
File Size Uploaded
PyGLM-1.1.5.tar.gz 351.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyglm 1.1.5
File
PyGLM-1.1.5-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details
PyGLM-1.1.5-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details
PyGLM-1.1.5-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
PyGLM-1.1.5-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
PyGLM-1.1.5-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
PyGLM-1.1.5-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
PyGLM-1.1.5-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
PyGLM-1.1.5-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details

Total release size: 6.7 MB

Release files / PyGLM-1.1.5.tar.gz

Download URL PyGLM-1.1.5.tar.gz
Size 351.1 kB
Tags Source
SHA-256 checksum
How to use checksums
053b889ed10d5d5a726b97b783a23b76f4659460ee40544b8ecaee8f071c5e6c
BLAKE2b-256 checksum
How to use checksums
601a11b6b0a680219cfa0cf9cb82df9183cc64d05355963a104701c3a67ca99d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp38-cp38-win_amd64.whl

Download URL PyGLM-1.1.5-cp38-cp38-win_amd64.whl
Size 867.4 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
a705f496c08a91bfd2d70d2c33225045d7b47de1a2d0359d613703e228260f6d
BLAKE2b-256 checksum
How to use checksums
c4248503671ee2af2208c653026bc0bd4919cc00f74f638d015edf71d111bd50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp38-cp38-win32.whl

Download URL PyGLM-1.1.5-cp38-cp38-win32.whl
Size 734.7 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
badc23c89fdbc60fcdfe2acbddf46643ed83417a94ae4e24edda6dc980140d9e
BLAKE2b-256 checksum
How to use checksums
7e9f1543275683ae0ddde4cd1356c9b069dcf292318899d7d3b00235c9f9b420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp37-cp37m-win_amd64.whl

Download URL PyGLM-1.1.5-cp37-cp37m-win_amd64.whl
Size 861.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
ff0e41722d23cf139979d95d15e4ddcb8b347edd9e5f8bd642b8959223c9e721
BLAKE2b-256 checksum
How to use checksums
e0dd4e988c30d1a470bb04766ffa191bfb66b42b3ef6a25cd4daf4bd1d546a9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp37-cp37m-win32.whl

Download URL PyGLM-1.1.5-cp37-cp37m-win32.whl
Size 732.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
c4ebb8473c0d8e21820ba29b07edc5a485a202c52b10d35c4df2647066be69c5
BLAKE2b-256 checksum
How to use checksums
e0f14eb6abfb69adfef7ab6ec5aa06dad64d220f5f5398905b128f2ac7298acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp36-cp36m-win_amd64.whl

Download URL PyGLM-1.1.5-cp36-cp36m-win_amd64.whl
Size 861.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
9b0bf557745342ef43bb7d8a9e8b3a7f4744aab56bfa8c1dcc103d34bc5c9c63
BLAKE2b-256 checksum
How to use checksums
3ed87f145a68af93c8f8265b76f6bc6c2e155669fb05863eb329341a9c6e0230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp36-cp36m-win32.whl

Download URL PyGLM-1.1.5-cp36-cp36m-win32.whl
Size 732.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
51f0984ffe67474ed5845bf919e735ef5469c6c7220490ebb6b224925503394c
BLAKE2b-256 checksum
How to use checksums
f3d247eb51c5d1e594286006dda0b3686ac8de63d86d10a208650f496e0bf135
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp35-cp35m-win_amd64.whl

Download URL PyGLM-1.1.5-cp35-cp35m-win_amd64.whl
Size 869.5 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
fc4bc9d5ffc2b393f9cccbb0a22e9ff69b595cd27959df3751f4f0778807d9cc
BLAKE2b-256 checksum
How to use checksums
48c1d55231d4600e9f01a025a7d5ae853a4f7c6b84b1cdc42093b941b2285948
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.5-cp35-cp35m-win32.whl

Download URL PyGLM-1.1.5-cp35-cp35m-win32.whl
Size 716.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
6ba3b2584805b399f8fc77b43464c13a30ec8f387c6469c017079c12eeb9ec64
BLAKE2b-256 checksum
How to use checksums
9a424209e83f92e87c96f10edb815b11ef6aff0b3cb565645a69d658e1040ef3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page