Skip to main content

OpenGL Mathematics library for Python

Project description

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!
(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 )

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

PyGLM-1.0.0.tar.gz (274.3 kB view details)

Uploaded Source

Built Distributions

PyGLM-1.0.0-cp37-cp37m-win_amd64.whl (875.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

PyGLM-1.0.0-cp37-cp37m-win32.whl (750.7 kB view details)

Uploaded CPython 3.7m Windows x86

PyGLM-1.0.0-cp36-cp36m-win_amd64.whl (875.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

PyGLM-1.0.0-cp36-cp36m-win32.whl (750.7 kB view details)

Uploaded CPython 3.6m Windows x86

PyGLM-1.0.0-cp35-cp35m-win_amd64.whl (895.4 kB view details)

Uploaded CPython 3.5m Windows x86-64

PyGLM-1.0.0-cp35-cp35m-win32.whl (749.1 kB view details)

Uploaded CPython 3.5m Windows x86

File details

Details for the file PyGLM-1.0.0.tar.gz.

File metadata

  • Download URL: PyGLM-1.0.0.tar.gz
  • Upload date:
  • Size: 274.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b41bc8831a089f1398b49a00bb1ce3700a799f97e837beb08829fa7bc643ad48
MD5 07c102ec015f630e6a14575aaa2a83da
BLAKE2b-256 4b8ed764f9448e3df421d7c23c46be937443b9f5b50368a2bcf088242cc7414e

See more details on using hashes here.

Provenance

File details

Details for the file PyGLM-1.0.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: PyGLM-1.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 875.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 e9c3e3efaca29c9bab20ad227f108470b59355c7df1487f3fd7807b8e6504704
MD5 b4a1aecb2abc02a6b2825dbf9f6d7b9e
BLAKE2b-256 fd9996bca5c117527d5ba96df57a870d0c31e80e959a8afeac99173113e40be6

See more details on using hashes here.

Provenance

File details

Details for the file PyGLM-1.0.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: PyGLM-1.0.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 750.7 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 53f6e6d367e946332805bac1bf20cdd35eea8a02210bac33ea3093d936f2520d
MD5 4632d66cfe1f66fbf07f9f85ac04d5e4
BLAKE2b-256 84fd5d77fb969631db67afafb2b0ce11e905468293c96ec7362352688a40ee87

See more details on using hashes here.

Provenance

File details

Details for the file PyGLM-1.0.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: PyGLM-1.0.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 875.5 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 41b21f3f4169d0f98ba136500e2e2a9e202f2bba67a67ce90174d843aa2573fc
MD5 10a687df06ca206049cbb92fba29953e
BLAKE2b-256 87dc520094cf5f20b6828a2acaf679d24e5e43612b6fb07147d09a0ea630ecce

See more details on using hashes here.

Provenance

File details

Details for the file PyGLM-1.0.0-cp36-cp36m-win32.whl.

File metadata

  • Download URL: PyGLM-1.0.0-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 750.7 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 14322cf25bd0e9fc35a5622ad697296c84c676aa62bb7d8fdcf06c5959c064e0
MD5 ad503317c0467f44231c303a56137569
BLAKE2b-256 b3c721587383da6d409e3fd83abceca9914915b52d2e25bf1d2ca65804f276d4

See more details on using hashes here.

Provenance

File details

Details for the file PyGLM-1.0.0-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: PyGLM-1.0.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 895.4 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 d48cc307e9b5d8b3629f47b0d1bb527d5adcb9dc08febeb98dabc8d62f8e9809
MD5 175ce0a45db7911ccc31c035f4491fec
BLAKE2b-256 a15035ad8fe310a77bd1e117262f51b8999dcb5bbe8fd815864803c2b5848717

See more details on using hashes here.

Provenance

File details

Details for the file PyGLM-1.0.0-cp35-cp35m-win32.whl.

File metadata

  • Download URL: PyGLM-1.0.0-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 749.1 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for PyGLM-1.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 85fa7e1fddb54d107fe494324e8399bc4164cf059d0bb7179981870b1ae3c47d
MD5 df51bf9881d81849d2fdccadc2954353
BLAKE2b-256 cb02ca23559d057fa2653504490621f23734ce09264be251abab5a6c5bdda980

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page