Skip to main content

OpenGL Mathematics library for Python

Project description

GLSL + Optional features + Python = PyGLM
A mathematics library for graphics programming.

Work in progress.

PyGLM is using GLM by G-Truc to offer a lot of the original features.
Currently, some features haven't yet found their way into PyGLM and some never will (such as unstable extensions).
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 10x 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.

Differences to glm

Instead of using double colons (::) for namespaces, periods (.) are used, so
glm::detail::vec2 becomes glm.detail.vec2.
You can also use the base namespace glm (e.g. glm.vec2).

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

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-0.6.0b1.tar.gz (265.3 kB view hashes)

Uploaded Source

Built Distributions

PyGLM-0.6.0b1-cp37-cp37m-win_amd64.whl (736.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

PyGLM-0.6.0b1-cp37-cp37m-win32.whl (592.3 kB view hashes)

Uploaded CPython 3.7m Windows x86

PyGLM-0.6.0b1-cp36-cp36m-win_amd64.whl (736.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

PyGLM-0.6.0b1-cp36-cp36m-win32.whl (592.3 kB view hashes)

Uploaded CPython 3.6m Windows x86

PyGLM-0.6.0b1-cp35-cp35m-win_amd64.whl (1.1 MB view hashes)

Uploaded CPython 3.5m Windows x86-64

PyGLM-0.6.0b1-cp35-cp35m-win32.whl (814.5 kB view hashes)

Uploaded CPython 3.5m Windows x86

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