{"id":16654777,"url":"https://github.com/zuzu-typ/pyglm","last_synced_at":"2025-10-24T20:36:00.524Z","repository":{"id":41547096,"uuid":"100879902","full_name":"Zuzu-Typ/PyGLM","owner":"Zuzu-Typ","description":"Fast OpenGL Mathematics (GLM) for Python","archived":false,"fork":false,"pushed_at":"2025-04-10T14:50:28.000Z","size":3426,"stargazers_count":225,"open_issues_count":12,"forks_count":31,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-15T05:07:06.145Z","etag":null,"topics":["cplusplus","efficient","fast","glm","glsl","high-performance","library","math-library","matrix","matrix-functions","numpy","opengl","opengl-mathematics","pip","pypi","pyrr","python","python3","quaternion","vector"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zuzu-Typ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-20T18:09:44.000Z","updated_at":"2025-04-12T04:42:47.000Z","dependencies_parsed_at":"2024-10-12T09:51:09.700Z","dependency_job_id":"8e58a0ec-04e9-4718-b51f-8759b6b67670","html_url":"https://github.com/Zuzu-Typ/PyGLM","commit_stats":{"total_commits":263,"total_committers":13,"mean_commits":20.23076923076923,"dds":0.0684410646387833,"last_synced_commit":"3ac2777ba34126432dd250996cfdf41aac4a2c7f"},"previous_names":[],"tags_count":105,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FPyGLM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FPyGLM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FPyGLM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FPyGLM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zuzu-Typ","download_url":"https://codeload.github.com/Zuzu-Typ/PyGLM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276447,"owners_count":22043867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cplusplus","efficient","fast","glm","glsl","high-performance","library","math-library","matrix","matrix-functions","numpy","opengl","opengl-mathematics","pip","pypi","pyrr","python","python3","quaternion","vector"],"created_at":"2024-10-12T09:51:00.475Z","updated_at":"2025-10-24T20:35:55.492Z","avatar_url":"https://github.com/Zuzu-Typ.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[//]: # (generated using SlashBack 0.2.0)\n\n# PyGLM  \n## OpenGL Mathematics \\(GLM\\) library for Python  \n**GLSL \\+ Optional features \\+ Python = PyGLM**  \n**A mathematics library for graphics programming\\.**  \n  \n**PyGLM** is a Python extension written in **C\\+\\+**\\.   \nBy using [GLM by G\\-Truc](https://glm.g-truc.net) under the hood, it manages to bring **glm's features** to Python\\.\u0026nbsp;\u0026nbsp;  \nSome features are unsupported \\(such as most unstable extensions\\)\\.  \nIf you encounter any issues or want to request a feature, please create an issue on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\\.  \n  \n**For a complete reference of the types and functions, please take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)**\\.  \n  \n## Tiny Documentation  \n### Why PyGLM?  \nBesides the obvious \\- being mostly compatible with **GLM** \\- PyGLM offers a variety of features for **vector** and **matrix manipulation**\\.  \nIt has a lot of possible use cases, including **3D\\-Graphics** \\(OpenGL, DirectX, \\.\\.\\.\\), **Physics** and more\\.  \n  \nAt the same time, it has **great performance**, usually being **a lot faster than numpy\\!** \\(see [end of page](#speed-comparison-to-numpy)\\)  \n\\(*depending on the individual function*\\)  \n### Installation  \n**PyGLM** supports **Windows**, **Linux**, **MacOS** and other operating systems\\.  \n  \nIt can be installed from the [PyPI](https://pypi.python.org/pypi/PyGLM) using [pip](https://pip.pypa.io/en/stable/):  \n``` batch\npip install pyglm\n ```  \nAnd finally imported and used:  \n``` python\nfrom pyglm import glm\n ```  \n*Changed in version 2\\.8*  \nWhen using PyGLM version *2\\.7\\.3* or earlier, use  \n``` python\ntry:\n    from pyglm import glm\nexcept ImportError:\n    import glm\n ```  \n  \n**Attention: Using ``` import glm ``` will be deprecated in PyGLM 3\\.0\\.**  \n### Using PyGLM  \nPyGLM's syntax is very similar to the original GLM's syntax\\.  \nThe module ``` glm ``` contains all of PyGLM's types and functions\\.  \n[Typing stubs](https://github.com/esoma/pyglm-typing) by [@\u003c!----\u003eesoma](https://github.com/esoma) are available in the ``` glm_typing ``` module\\.  \n  \nFor more information, take a look at the [wiki](https://github.com/Zuzu-Typ/PyGLM/wiki)\\.  \n#### License requirements  \nPlease make sure to **include COPYING** in your project when you use PyGLM\\!  \n\\(this is especially relevant for **binary distributions**, e\\.g\\. \\*\\.exe\\)  \n  \nYou can do so by copying the ``` COPYING ``` file \\(or it's contents\\) to your project\\.  \n#### Differences to glm  \nInstead of using double colons \\(**::**\\) for namespaces, periods \\(**\\.**\\) are used, so  \n``` glm::vec2 ``` becomes ``` glm.vec2 ```\\.  \n  \nPyGLM supports the [buffer protocol](https://docs.python.org/3/c-api/buffer.html), meaning its compitible to other objects that support the buffer protocol,  \nsuch as ``` bytes ``` or ``` numpy.array ```   \n\\(for example you can convert a glm matrix to a numpy array and vice versa\\)\\.  \nPyGLM is also capable of interpreting iterables \\(such as tuples\\) as vectors, so e\\.g\\. the following equasion is possible:  \n``` python\nresult = glm.vec2(1) * (2, 3)\n ```  \n*Note: This feature might not or only partially be available in PyGLM versions prior to 2\\.0\\.0*  \n  \nPyGLM doesn't support precision qualifiers\\. All types use the default precision \\(``` packed_highp ```\\)\\.  \n  \nIf a glm function normally accepts ``` float ``` and ``` double ``` arguments, the higher precision \\(``` double ```\\) is used\\.  \n  \nThere is no way to set preprocessor definitions \\(macros\\)\\.  \nIf \\- for example \\- you need to use the left handed coordinate system, you have to use **\\*LH**, so  \n``` glm.perspective ``` becomes ``` glm.perspectiveLH ```\\.  \n  \nAll types are initialized by default to avoid memory access violations\\.  \n\\(i\\.e\\. the macro ``` GLM_FORCE_CTOR_INIT ``` is defined\\)  \n  \nIn case you need the size of a PyGLM datatype, you can use   \n``` python\nglm.sizeof(\u003ctype\u003e)\n ```  \n  \nThe function ``` glm.identity ``` requires a matrix type as it's argument\\.  \n  \nThe function ``` glm.frexp(x, exp) ``` returns a tuple ``` (m, e) ```, if the input arguments are numerical\\.  \nThis function may issue a ``` UserWarning ```\\. You can silence this warning using ``` glm.silence(1) ```\\.  \n  \nThe function ``` glm.value_ptr(x) ``` returns a ctypes pointer of the respective type\\.  \nI\\.e\\. if the datatype of ``` x ``` is ``` float ```, then a ``` c_float ``` pointer will be returned\\.  \nLikewise the reverse\\-functions \\(such as ``` make_vec2(ptr) ```\\) will take a ctypes pointer as their argument  \nand return \\(in this case\\) a 2 component vector of the pointers underlying type\\.  \n  \n``` glm.silence(ID) ``` can be used to silence specific warnings\\.  \nSupplying an id of 0 will silence all warnings\\.  \n  \n  \n### FAQ  \n#### How to pass the matrices generated by PyGLM to OpenGL functions?  \nYou will find an overview on the \\[[Passing data to external libs](https://github.com/Zuzu-Typ/PyGLM/wiki/Passing-data-to-external-libs/)\\] page\\.  \n  \n#### Types and functions are not available after installing from the PyPI using ``` pip install glm ```   \nMost likely you've installed [glm](https://pypi.org/project/glm/), a JSON parser and not [PyGLM](https://pypi.org/project/PyGLM/) \\(or a very early version of PyGLM\\)\\.  \nThe correct install command is:  \n``` batch\npip install pyglm\n ```  \n  \n#### Why is *\u0026lt;experimental extension name here\u0026gt;* not supported?  \nI prefer not to add too many experimental extensions to PyGLM, especially as they might change or be removed in the future and it is simply too much effort for me to keep up with all that\\.\u0026nbsp;\u0026nbsp;  \nIf you **need a specific experimental extension**, feel free to **submit a feature request** on the [issue tracker](https://github.com/Zuzu-Typ/PyGLM/issues)\\.\u0026nbsp;\u0026nbsp;  \nI try adding them on a one\\-by\\-one basis\\.  \n  \n### Short example  \n``` Python\nfrom pyglm import glm\n\n# Create a 3D vector\nv1 = glm.vec3(1, 2, 3)\nv2 = glm.vec3(4, 5, 6)\n\n# Vector addition\nv3 = v1 + v2\nprint(f\"Vector addition: {v3}\")\n# Vector addition: vec3(            5,            7,            9 )\n\n# Vector cross product\n# -\u003e The resulting vector is perpendicular to v1 and v2.\ncross_product = glm.cross(v1, v2)\nprint(f\"Cross product: {cross_product}\")\n# Cross product: vec3(           -3,            6,           -3 )\n\n# Vector dot product\n# -\u003e If the dot product is equal to 0, the two inputs are perpendicular.\ndot_product = glm.dot(v1, cross_product)\nprint(f\"Dot product: {dot_product}\")\n# Dot product: 0.0\n\n# Create a 4x4 identity matrix\nmatrix = glm.mat4()\nprint(f\"Identity matrix:\\n{matrix}\")\n# Identity matrix:\n# [            1 ][            0 ][            0 ][            0 ]\n# [            0 ][            1 ][            0 ][            0 ]\n# [            0 ][            0 ][            1 ][            0 ]\n# [            0 ][            0 ][            0 ][            1 ]\n\n# Rotate the matrix around the Z-axis\nangle_in_radians = glm.radians(45)  # Convert 45 degrees to radians\nrotation_matrix = glm.rotate(matrix, angle_in_radians, glm.vec3(0, 0, 1))\nprint(f\"Rotation matrix (45 degrees around Z-axis):\\n{rotation_matrix}\")\n# Rotation matrix (45 degrees around Z-axis):\n# [     0.707107 ][    -0.707107 ][            0 ][            0 ]\n# [     0.707107 ][     0.707107 ][            0 ][            0 ]\n# [            0 ][            0 ][            1 ][            0 ]\n# [            0 ][            0 ][            0 ][            1 ]\n\n# Apply the rotation to a vector\n# -\u003e We use a vec4 with the w-component (given vec4(x, y, z, w)) set to 1, \n#    to put v1 into homogenous coordinates.\nrotated_vector = rotation_matrix * glm.vec4(v1, 1)\nprint(f\"Rotated vector: {rotated_vector}\")\n# Rotated vector: vec4(    -0.707107,      2.12132,            3,            1 )\n ```  \n  \n### PyGLM in action  \nWant to see what PyGLM can do?  \nTake a look at the [examples](https://github.com/Zuzu-Typ/LearnOpenGL-Python) from the popular LearnOpenGL tutorials by Joey De Vries running in Python using PyGLM\\.  \n![LearnOpenGL](https://raw.githubusercontent.com/Zuzu-Typ/PyGLM/master/LearnOpenGL.png)  \n  \n### Speed comparison to numpy  \nThe following is the output generated by [test/PyGLM vs Numpy\\.py](https://github.com/Zuzu-Typ/PyGLM/blob/master/test/PyGLM_vs_NumPy.py)  \n``` \nEvaluating performance of PyGLM compared to NumPy.\n\nRunning on platform 'win32'.\n\nPython version:\n3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)]\n\nComparing the following module versions:\nPyGLM (DEFAULT) version 2.7.2\n vs\nNumPy version 2.1.2\n________________________________________________________________________________\n\nThe following table shows information about a task to be achieved and the time\nit took when using the given module. Lower time is better.\nEach task is repeated ten times per module, only showing the best (i.e. lowest)\nvalue.\n\n\n+----------------------------------------+------------+------------+-----------+\n| Description                            | PyGLM time | NumPy time |     ratio |\n+----------------------------------------+------------+------------+-----------+\n| 3 component vector creation            |            |            |           |\n| (100,000 times)                        |        8ms |       30ms |     3.78x |\n+----------------------------------------+------------+------------+-----------+\n| 3 component vector creation with       |            |            |           |\n| custom components                      |            |            |           |\n| (50,000 times)                         |        8ms |       33ms |     4.05x |\n+----------------------------------------+------------+------------+-----------+\n| dot product                            |            |            |           |\n| (50,000 times)                         |        3ms |       46ms |    13.53x |\n+----------------------------------------+------------+------------+-----------+\n| cross product                          |            |            |           |\n| (25,000 times)                         |        2ms |      523ms |   288.77x |\n+----------------------------------------+------------+------------+-----------+\n| L2-Norm of 3 component vector          |            |            |           |\n| (100,000 times)                        |        5ms |      249ms |    49.05x |\n+----------------------------------------+------------+------------+-----------+\n| 4x4 matrix creation                    |            |            |           |\n| (50,000 times)                         |        5ms |       15ms |     3.03x |\n+----------------------------------------+------------+------------+-----------+\n| 4x4 identity matrix creation           |            |            |           |\n| (100,000 times)                        |        6ms |      222ms |    36.61x |\n+----------------------------------------+------------+------------+-----------+\n| 4x4 matrix transposition               |            |            |           |\n| (50,000 times)                         |        3ms |       23ms |     6.73x |\n+----------------------------------------+------------+------------+-----------+\n| 4x4 multiplicative inverse             |            |            |           |\n| (50,000 times)                         |        4ms |      336ms |    90.30x |\n+----------------------------------------+------------+------------+-----------+\n| 3 component vector addition            |            |            |           |\n| (100,000 times)                        |        5ms |       52ms |    10.11x |\n+----------------------------------------+------------+------------+-----------+\n| 4x4 matrix multiplication              |            |            |           |\n| (100,000 times)                        |        8ms |       55ms |     6.85x |\n+----------------------------------------+------------+------------+-----------+\n| 4x4 matrix x vector multiplication     |            |            |           |\n| (100,000 times)                        |        6ms |      152ms |    23.39x |\n+----------------------------------------+------------+------------+-----------+\n| TOTAL                                  |      0.06s |      1.74s |    26.97x |\n+----------------------------------------+------------+------------+-----------+\n ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzuzu-typ%2Fpyglm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzuzu-typ%2Fpyglm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzuzu-typ%2Fpyglm/lists"}