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.0

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.0
File Size Uploaded
PyGLM-1.1.0.tar.gz 281.9 kB Details

Built distributions (wheels)

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

Total release size: 6.8 MB

Release files / PyGLM-1.1.0.tar.gz

Download URL PyGLM-1.1.0.tar.gz
Size 281.9 kB
Tags Source
SHA-256 checksum
How to use checksums
637dd7835d2c103e5884aa3ab4cf9e24e2229f691e2a338d2269198ec3c3b1a1
BLAKE2b-256 checksum
How to use checksums
09dc92e7ffce65c43c8b783e2a7e0831d9a48663cdc2e06c7d4a37ae3706deea
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.0-cp38-cp38-win_amd64.whl

Download URL PyGLM-1.1.0-cp38-cp38-win_amd64.whl
Size 885.4 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
218ac60ae923c733f03e4bfc9f7223578aea08a01ed91875e56ddd931dc83c66
BLAKE2b-256 checksum
How to use checksums
67241310931b2767ff09dca6a88978b44e67b3499cdb1fa7ac47fc5da039e346
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.0-cp38-cp38-win32.whl

Download URL PyGLM-1.1.0-cp38-cp38-win32.whl
Size 757.9 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
64cafccbf35e3c20368fa04188926ea61b7d8a5313442d8a42d149a3228e2ffc
BLAKE2b-256 checksum
How to use checksums
b22516fc3087fc7d047efc9616b9e85a626cff7571cc32c8a23dd57ed1e3fd52
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.0-cp37-cp37m-win_amd64.whl

Download URL PyGLM-1.1.0-cp37-cp37m-win_amd64.whl
Size 879.6 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
e92f9661914e718a8d91befd2f9eab1b837ead4a167e87c489e1263e2015adbf
BLAKE2b-256 checksum
How to use checksums
db2b0c3e732a3ae9003f1574c43df96e30b5dde8af5569cc11fab890d1f41f62
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.0-cp37-cp37m-win32.whl

Download URL PyGLM-1.1.0-cp37-cp37m-win32.whl
Size 753.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
ae291010878f0317a6fe817cd50331a82078e737e2af6f15e4f219fc86092452
BLAKE2b-256 checksum
How to use checksums
585c244a678f47f4b8a66050242cf150b16d5cf1079d48df31ede0eb9e3031d3
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.0-cp36-cp36m-win_amd64.whl

Download URL PyGLM-1.1.0-cp36-cp36m-win_amd64.whl
Size 879.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
b77e2163648c9f6bbf9ed01f64883cc80343e56531dad360cfed5758242e2883
BLAKE2b-256 checksum
How to use checksums
8a74e748a4e9065b42948be060875bbac139d2b6f48fb27c722684dce3f45871
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.0-cp36-cp36m-win32.whl

Download URL PyGLM-1.1.0-cp36-cp36m-win32.whl
Size 753.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
02eb2f09f6c1de0bc95dab05a45187cb65cfcb496382b53d36c270ac01cacc78
BLAKE2b-256 checksum
How to use checksums
8e2e6ec78515fe32f5d57c82ad87b87f8b70c40d8d86f84aac3474d3dcf1e9a8
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.0-cp35-cp35m-win_amd64.whl

Download URL PyGLM-1.1.0-cp35-cp35m-win_amd64.whl
Size 899.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
351c01382963c01eea53be29447cdf75b7a8daa7e9151a5c27c2db1b3a6d723d
BLAKE2b-256 checksum
How to use checksums
a768f00ab3acd66843d618250d8d732006f9ad45ed7c5305650325b17fe899de
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.0-cp35-cp35m-win32.whl

Download URL PyGLM-1.1.0-cp35-cp35m-win32.whl
Size 752.5 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
bd5445628f5985421dd18bb7afcfa6df9b8be84daf94d60accfed533d3c64323
BLAKE2b-256 checksum
How to use checksums
fa90b3fabb7becea0d270d151d4fa2fe0f22bb37c97f3a78b18d117c85eb0167
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