Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Nuget Badge Build status codecov GuardRails badge

GlmNet is a .NET version of the excellent OpenGL Mathematics library (GLM).

The OpenGL Mathematics Library is open source, licensed under the MIT license. I would like to thank Christophe Riccio for his permission to wrap the library.

Development Status

Important: I am developing GlmNet as I need it - so there are very few advanced features from GLM ported over yet. Please do feel free to fork the code and add the features as you need them - if you create pull requests I'll merge them into the main branch.


Install it with Nuget:

PM> Install-Package GlmNet

That's all there is to it!


GlmNet attempts to be as syntactically similar to GLM as possible. Examples are:

mat4 projectionMatrix = glm.perspective(rads, (float)Width / (float)Height, 0.1f, 100.0f);
mat4 viewMatrix = glm.translate(new mat4(1.0f), new vec3(0.0f, 0.0f, -5.0f));
mat4 modelMatrix = glm.scale(new mat4(1.0f), new vec3(0.5f));


Column Major Matrices

GlmNet matrices are Column Major. This is because GLM attempts to mimic GLSL as closely as possible.

    | a b c |
    | d e f | = |M|
    | g h i |

This means M[0] gives column 0, i.e:

    | a |
    | d |
    | g |

M[1][2] or M[1,2] gives column 1, row 2, i.e:


Column major matrices are used in OpenGL, row major in DirectX. Many C++ libraries are row major, be aware that GlmNet is column major. This means that as OpenGL vectors are typically columns, you multiply in the order matrix * vector:

    a = m * v

Rather than v * m.

Matrix Initialisation

Matrices are NOT initialised to the identity. Use the identity function. All types are based on floats. Matrix elements are references as multidimensional arrays when you want to change them, e.g:

// Get data from matrices like this:
var element = matrix[1][2];

// ..or this..
var element = matrix[1,2];

// But SET data in a matrix like this:
matrix[1,2] = element;

All angles in GlmNet are expected to be in radians - no conversion to or from degrees is ever done.

Code Structure

glm - A copy of the latest version of the OpenGL Mathematics library. source - The source code for GlmNet.

API / Supported Features

GLM Core

  • Vectors: vec2, vec3, vec4
  • Matrices: mat2, mat3, mat4
  • Transformations: scale, rotate, translate
  • Projections: perspective, frustum
  • Matrix * Matrix
  • Matrix * Vector

Angle and Trigonometry Functions

  • acos
  • acosh
  • asin
  • asinh
  • atan
  • atanh
  • cos
  • cosh
  • degrees
  • radians
  • sin
  • sinh
  • tan
  • tanh

Geometric Functions

  • dot
  • cross
  • normalize

Not Implemented

  • distance
  • faceforward
  • length
  • reflect
  • refract

Matrix Functions

  • inverse

Not implemented

  • determinant
  • matrixCompMult
  • outerProduct
  • transpose_type

GTC Extensions (Stable)


All functions are supported. Angles are always in radians.

  • frustum
  • infinitePerspective
  • lookAt
  • ortho
  • perspective
  • perspectiveFov
  • pickMatrix
  • project
  • rotate
  • scale
  • translate
  • tweakedInfinitePerspective
  • unProject

Developer Guide

Building & Testing

As long as the correct components have be installed for Visual Studio, you should be able to just open the main ./source/GlmNet/GlmtNet.sln solution to build, test and run any of the code or samples.

You can also use the following scripts to run the processes:

Script Notes
config.ps1 Ensure your machine can run builds by installing necessary components such as nunit. Should only need to be run once.
build.ps1 Build all solutions.
test.ps1 Run all tests.
coverage.ps1 Create a coverage report for the main GlmNet project. Reports are written to ./artifacts/coverage

These scripts will generate various artifacts which may be useful to review:

  \tests                  # NUnit Test Reports
  \coverage               # Coverage Reports


To run the full pipeline, the build system should have the following environment variables set:

Environment Variable Usage
CODECOV_TOKEN The upload token for


Update the solution version in the AssemblyInfo. Create a git tag which matches this new version. Then push:

git push --follow-tags

As long as the build succeeds, the presence of the tag will trigger the release.


GlmNet is a .NET version of the excellent OpenGL Mathematics library (GLM).






Sponsor this project



No packages published