GLM is a header-only library, and thus does not need to be compiled. We can use GLM's implementation of GLSL's mathematics functionality by including the `<glm/glm.hpp>` header:
To extend the feature set supported by GLM and keeping the library as close to GLSL as possible, new features are implemented as extensions that can be included thought a separated header:
*Note: Including `<glm/glm.hpp>` and `<glm/ext.hpp>` is convenient but pull a lot of code which will significantly increase build time, particularly if these files are included in all source files. We may prefer to use the approaches describe in the two following sections to keep the project build fast.*
GLM relies on C++ templates heavily, and may significantly increase compilation times for projects that use it. Hence, user projects could only include the features they actually use. Following is the list of all the core features, based on GLSL specification, headers:
GLM does not depend on external libraries or headers such as `<GL/gl.h>`, [`<GL/glcorearb.h>`](http://www.opengl.org/registry/api/GL/glcorearb.h), `<GLES3/gl3.h>`, `<GL/glu.h>`, or `<windows.h>`.
When included, GLM will first automatically detect the compiler used, the C++ standard supported, the compiler arguments used to configure itself matching the build environment.
GLM will automatically take advantage of compilers’ language extensions when enabled. To increase cross platform compatibility and to avoid compiler extensions, a programmer can define `GLM_FORCE_CXX98` before
any inclusion of `<glm/glm.hpp>` to restrict the language feature set C++98:
Often, this behaviour is not desirable but following the spirit of the library, this is the default behavior in GLM. However, GLM 0.9.6 introduced the define `GLM_FORCE_EXPLICIT_CTOR` to require explicit conversion for GLM types.
To push further the software performance, a programmer can define `GLM_FORCE_INLINE` before any inclusion of `<glm/glm.hpp>` to force the compiler to inline GLM code.
Every object type has the property called alignment requirement, which is an integer value (of type `std::size_t`, always a power of 2) representing the number of bytes between successive addresses at which objects of this type can be allocated. The alignment requirement of a type can be queried with alignof or `std::alignment_of`. The pointer alignment function `std::align` can be used to obtain a suitably-aligned pointer within some buffer, and `std::aligned_storage` can be used to obtain suitably-aligned storage.
Each object type imposes its alignment requirement on every object of that type; stricter alignment (with larger alignment requirement) can be requested using C++11 `alignas`.
In order to satisfy alignment requirements of all non-static members of a class, padding may be inserted after some of its members.
GLM supports both packed and aligned types. Packed types allow filling data structure without inserting extra padding. Aligned GLM types align addresses based on the size of the value type of a GLM type.
For example, if a program is compiled with Visual Studio using `/arch:AVX`, GLM will detect this argument and generate code using AVX instructions automatically when available.
The use of intrinsic functions by GLM implementation can be avoided using the define `GLM_FORCE_PURE` before any inclusion of GLM headers. This can be particularly useful if we want to rely on C++14 `constexpr`.
Some platforms (Dreamcast) doesn't support double precision floating point values. To compile on such platforms, GCC has the `--m4-single-only` build argument. When defining `GLM_FORCE_SINGLE_ONLY` before including GLM headers, GLM releases the requirement of double precision floating point values support. Effectivement, all the float64 types are no longer defined and double behaves like float.
Shader languages like GLSL often feature so-called swizzle expressions, which may be used to freely select and arrange a vector's components. For example, `variable.x`, `variable.xzy` and `variable.zxyy` respectively form a scalar, a 3D vector and a 4D vector. The result of a swizzle expression in GLSL can be either an R-value or an L-value. Swizzle expressions can be written with characters from exactly one of `xyzw` (usually for positions), `rgba` (usually for colors), and `stpq` (usually for texture coordinates).
Visual C++, GCC and Clang support, as a _non-standard language extension_, anonymous `struct`s as `union` members. This permits a powerful swizzling implementation that both allows L-value swizzle expressions and GLSL-like syntax. To use this feature, the language extension must be enabled by a supporting compiler and `GLM_FORCE_SWIZZLE` must be `#define`d.
```cpp
#define GLM_FORCE_SWIZZLE
#include <glm/glm.hpp>
// Only guaranteed to work with Visual C++!
// Some compilers that support Microsoft extensions may compile this.
This version returns implementation-specific objects that _implicitly convert_ to their respective vector types. As a consequence of this design, these extra types **can't be directly used** as C++ function arguments; they must be converted through constructors or `operator()`.
vec4 ClampedB = clamp(vec4(Color.rgba), 0.f, 1.f); // OK
// Explicit conversion through operator()
vec4 ClampedC = clamp(Color.rgba(), 0.f, 1.f); // OK
}
```
*Note: The implementation has a caveat: Swizzle operator types must be different on both size of the equal operator or the operation will fail. There is no known fix for this issue to date*
Following GLSL specifications, GLM supports three sets of components to access vector types member: x, y, z, w; r, g, b, a; and s, t, p, q.
Also, this is making vector component very expressive in the code, it may make debugging vector types a little cubersom as the debuggers will typically display three time the values for each compoenents due to the existance of the three sets.
By default, OpenGL is using a right handed coordinate system. However, others APIs such as Direct3D have done different choice and relies on the left handed coordinate system.
This function returns an `int` however this function typically interacts with STL `size_t` based code. GLM provides `GLM_FORCE_SIZE_T_LENGTH` pre-processor configuration so that member functions `length()` return a `size_t`.
By default, GLM follows the GLSL specification as accurately as possible however it's possible to relax these rules using `GLM_FORCE_UNRESTRICTED_GENTYPE` define.
When using /W4 on Visual C++ or -Wpedantic on GCC, for example, the compilers will generate warnings for using C++ language extensions (/Za with Visual C++) such as anonymous struct.
GLM relies on anonymous structs for swizzle operators and aligned vector types. To silent those warnings define `GLM_FORCE_SILENT_WARNINGS` before including GLM headers.
This extension exposes support for `min` and `max` functions taking more than two scalar arguments. Also, it adds `fmin` and `fmax` variants which prevents `NaN` propagation.
This extension exposes single-precision floating point vector with 1 component using various precision in term of ULPs: `lowp_vec1`, `mediump_vec1` and `highp_vec1`.
Include `<glm/ext/vector_float1_precision.hpp>` to use these features.
#### 3.4.2. GLM_EXT_vector_float2_precision
This extension exposes single-precision floating point vector with 2 components using various precision in term of ULPs: `lowp_vec2`, `mediump_vec2` and `highp_vec2`.
Include `<glm/ext/vector_float2_precision.hpp>` to use these features.
#### 3.4.3. GLM_EXT_vector_float3_precision
This extension exposes single-precision floating point vector with 3 components using various precision in term of ULPs: `lowp_vec3`, `mediump_vec3` and `highp_vec3`.
Include `<glm/ext/vector_float3_precision.hpp>` to use these features.
#### 3.4.4. GLM_EXT_vector_float4_precision
This extension exposes single-precision floating point vector with 4 components using various precision in term of ULPs: `lowp_vec4`, `mediump_vec4` and `highp_vec4`.
Include `<glm/ext/vector_float4_precision.hpp>` to use these features.
#### 3.4.5. GLM_EXT_vector_double1_precision
This extension exposes double-precision floating point vector with 1 component using various precision in term of ULPs: `lowp_dvec1`, `mediump_dvec1` and `highp_dvec1`.
Include `<glm/ext/vector_double1_precision.hpp>` to use these features.
#### 3.4.6. GLM_EXT_vector_double2_precision
This extension exposes double-precision floating point vector with 2 components using various precision in term of ULPs: `lowp_dvec2`, `mediump_dvec2` and `highp_dvec2`.
Include `<glm/ext/vector_double2_precision.hpp>` to use these features.
#### 3.4.7. GLM_EXT_vector_double3_precision
This extension exposes double-precision floating point vector with 3 components using various precision in term of ULPs: `lowp_dvec3`, `mediump_dvec3` and `highp_dvec3`.
Include `<glm/ext/vector_double3_precision.hpp>` to use these features.
#### 3.4.8. GLM_EXT_vector_double4_precision
This extension exposes double-precision floating point vector with 4 components using various precision in term of ULPs: `lowp_dvec4`, `mediump_dvec4` and `highp_dvec4`.
Include `<glm/ext/vector_double4_precision.hpp>` to use these features.
This extension exposes support for `min` and `max` functions taking more than two vector arguments. Also, it adds `fmin` and `fmax` variants which prevents `NaN` propagation.
This extension exposes single-precision floating point vector with 3 columns by 4 rows: `mat3x4`.
Include `<glm/ext/matrix_float3x4.hpp>` to use these features.
#### 3.6.7. GLM_EXT_matrix_float4x2
This extension exposes single-precision floating point vector with 4 columns by 2 rows: `mat4x2`.
Include `<glm/ext/matrix_float4x2.hpp>` to use these features.
#### 3.6.8. GLM_EXT_matrix_float4x3
This extension exposes single-precision floating point vector with 4 columns by 3 rows: `mat4x3`.
Include `<glm/ext/matrix_float4x3.hpp>` to use these features.
#### 3.6.9. GLM_EXT_matrix_float4x4
This extension exposes single-precision floating point vector with 4 columns by 4 rows: `mat4x4`.
Include `<glm/ext/matrix_float4x4.hpp>` to use these features.
#### 3.6.10. GLM_EXT_matrix_double2x2
This extension exposes double-precision floating point vector with 2 columns by 2 rows: `dmat2x2`.
Include `<glm/ext/matrix_double2x2.hpp>` to use these features.
#### 3.6.11. GLM_EXT_matrix_double2x3
This extension exposes double-precision floating point vector with 2 columns by 3 rows: `dmat2x3`.
Include `<glm/ext/matrix_double2x3.hpp>` to use these features.
#### 3.6.12. GLM_EXT_matrix_double2x4
This extension exposes double-precision floating point vector with 2 columns by 4 rows: `dmat2x4`.
Include `<glm/ext/matrix_double2x4.hpp>` to use these features.
#### 3.6.13. GLM_EXT_matrix_double3x2
This extension exposes double-precision floating point vector with 3 columns by 2 rows: `dmat3x2`.
Include `<glm/ext/matrix_double3x2.hpp>` to use these features.
#### 3.6.14. GLM_EXT_matrix_double3x3
This extension exposes double-precision floating point vector with 3 columns by 3 rows: `dmat3x3`.
Include `<glm/ext/matrix_double3x3.hpp>` to use these features.
#### 3.6.15. GLM_EXT_matrix_double3x4
This extension exposes double-precision floating point vector with 3 columns by 4 rows: `dmat3x4`.
Include `<glm/ext/matrix_double3x4.hpp>` to use these features.
#### 3.6.16. GLM_EXT_matrix_double4x2
This extension exposes double-precision floating point vector with 4 columns by 2 rows: `dmat4x2`.
Include `<glm/ext/matrix_double4x2.hpp>` to use these features.
#### 3.6.17. GLM_EXT_matrix_double4x3
This extension exposes double-precision floating point vector with 4 columns by 3 rows: `dmat4x3`.
Include `<glm/ext/matrix_double4x3.hpp>` to use these features.
#### 3.6.18. GLM_EXT_matrix_double4x4
This extension exposes double-precision floating point vector with 4 columns by 4 rows: `dmat4x4`.
Include `<glm/ext/matrix_double4x4.hpp>` to use these features.
### <a name="section3_7"></a> 3.7. Matrix types with precision qualifiers
#### 3.7.1. GLM_EXT_matrix_float2x2_precision
This extension exposes single-precision floating point vector with 2 columns by 2 rows using various precision in term of ULPs: `lowp_mat2x2`, `mediump_mat2x2` and `highp_mat2x2`.
Include `<glm/ext/matrix_float2x2_precision.hpp>` to use these features.
#### 3.7.2. GLM_EXT_matrix_float2x3_precision
This extension exposes single-precision floating point vector with 2 columns by 3 rows using various precision in term of ULPs: `lowp_mat2x3`, `mediump_mat2x3` and `highp_mat2x3`.
Include `<glm/ext/matrix_float2x3_precision.hpp>` to use these features.
#### 3.7.3. GLM_EXT_matrix_float2x4_precision
This extension exposes single-precision floating point vector with 2 columns by 4 rows using various precision in term of ULPs: `lowp_mat2x4`, `mediump_mat2x4` and `highp_mat2x4`.
Include `<glm/ext/matrix_float2x4_precision.hpp>` to use these features.
#### 3.7.4. GLM_EXT_matrix_float3x2_precision
This extension exposes single-precision floating point vector with 3 columns by 2 rows using various precision in term of ULPs: `lowp_mat3x2`, `mediump_mat3x2` and `highp_mat3x2`.
Include `<glm/ext/matrix_float3x2_precision.hpp>` to use these features.
#### 3.7.5. GLM_EXT_matrix_float3x3_precision
This extension exposes single-precision floating point vector with 3 columns by 3 rows using various precision in term of ULPs: `lowp_mat3x3`, `mediump_mat3x3` and `highp_mat3x3`.
Include `<glm/ext/matrix_float3x3_precision.hpp>` to use these features.
#### 3.7.6. GLM_EXT_matrix_float3x4_precision
This extension exposes single-precision floating point vector with 3 columns by 4 rows using various precision in term of ULPs: `lowp_mat3x4`, `mediump_mat3x4` and `highp_mat3x4`.
Include `<glm/ext/matrix_float3x4_precision.hpp>` to use these features.
#### 3.7.7. GLM_EXT_matrix_float4x2_precision
This extension exposes single-precision floating point vector with 4 columns by 2 rows using various precision in term of ULPs: `lowp_mat4x2`, `mediump_mat4x2` and `highp_mat4x2`.
Include `<glm/ext/matrix_float4x2_precision.hpp>` to use these features.
#### 3.7.8. GLM_EXT_matrix_float4x3_precision
This extension exposes single-precision floating point vector with 4 columns by 3 rows using various precision in term of ULPs: `lowp_mat4x3`, `mediump_mat4x3` and `highp_mat4x3`.
Include `<glm/ext/matrix_float4x3_precision.hpp>` to use these features.
#### 3.7.9. GLM_EXT_matrix_float4x4_precision
This extension exposes single-precision floating point vector with 4 columns by 4 rows using various precision in term of ULPs: `lowp_mat4x4`, `mediump_mat4x4` and `highp_mat4x4`.
Include `<glm/ext/matrix_float4x4_precision.hpp>` to use these features.
#### 3.7.10. GLM_EXT_matrix_double2x2_precision
This extension exposes double-precision floating point vector with 2 columns by 2 rows using various precision in term of ULPs: `lowp_dmat2x2`, `mediump_dmat2x2` and `highp_dmat2x2`.
Include `<glm/ext/matrix_double2x2_precision.hpp>` to use these features.
#### 3.7.11. GLM_EXT_matrix_double2x3_precision
This extension exposes double-precision floating point vector with 2 columns by 3 rows using various precision in term of ULPs: `lowp_dmat2x3`, `mediump_dmat2x3` and `highp_dmat2x3`.
Include `<glm/ext/matrix_double2x3_precision.hpp>` to use these features.
#### 3.7.12. GLM_EXT_matrix_double2x4_precision
This extension exposes double-precision floating point vector with 2 columns by 4 rows using various precision in term of ULPs: `lowp_dmat2x4`, `mediump_dmat2x4` and `highp_dmat2x4`.
Include `<glm/ext/matrix_double2x4_precision.hpp>` to use these features.
#### 3.7.13. GLM_EXT_matrix_double3x2_precision
This extension exposes double-precision floating point vector with 3 columns by 2 rows using various precision in term of ULPs: `lowp_dmat3x2`, `mediump_dmat3x2` and `highp_dmat3x2`.
Include `<glm/ext/matrix_double3x2_precision.hpp>` to use these features.
#### 3.7.14. GLM_EXT_matrix_double3x3_precision
This extension exposes double-precision floating point vector with 3 columns by 3 rows using various precision in term of ULPs: `lowp_dmat3x3`, `mediump_dmat3x3` and `highp_dmat3x3`.
Include `<glm/ext/matrix_double3x3_precision.hpp>` to use these features.
#### 3.7.15. GLM_EXT_matrix_double3x4_precision
This extension exposes double-precision floating point vector with 3 columns by 4 rows using various precision in term of ULPs: `lowp_dmat3x4`, `mediump_dmat3x4` and `highp_dmat3x4`.
Include `<glm/ext/matrix_double3x4_precision.hpp>` to use these features.
#### 3.7.16. GLM_EXT_matrix_double4x2_precision
This extension exposes double-precision floating point vector with 4 columns by 2 rows using various precision in term of ULPs: `lowp_dmat4x2`, `mediump_dmat4x2` and `highp_dmat4x2`.
Include `<glm/ext/matrix_double4x2_precision.hpp>` to use these features.
#### 3.7.17. GLM_EXT_matrix_double4x3_precision
This extension exposes double-precision floating point vector with 4 columns by 3 rows using various precision in term of ULPs: `lowp_dmat4x3`, `mediump_dmat4x3` and `highp_dmat4x3`.
Include `<glm/ext/matrix_double4x3_precision.hpp>` to use these features.
#### 3.7.18. GLM_EXT_matrix_double4x4_precision
This extension exposes double-precision floating point vector with 4 columns by 4 rows using various precision in term of ULPs: `lowp_dmat4x4`, `mediump_dmat4x4` and `highp_dmat4x4`.
Include `<glm/ext/matrix_double4x4_precision.hpp>` to use these features.
This extension exposes single-precision floating point quaternion using various precision in term of ULPs: `lowp_quat`, `mediump_quat` and `highp_quat`.
Include `<glm/ext/quaternion_float_precision.hpp>` to use these features.
This extension exposes double-precision floating point quaternion using various precision in term of ULPs: `lowp_dquat`, `mediump_dquat` and `highp_dquat`.
Include `<glm/ext/quaternion_double_precision.hpp>` to use these features.
GLM extends the core GLSL feature set with extensions. These extensions include: quaternion, transformation, spline, matrix inverse, color spaces, etc.
For example, the `lookAt` function generates a transformation matrix that projects world coordinates into eye coordinates suitable for projection matrices (e.g. `perspective`, `ortho`). See the OpenGL compatibility specifications for more information about the layout of these generated matrices.
The matrices generated by this extension use standard OpenGL fixed-function conventions. For example, the `lookAt` function generates a transform from world space into the specific eye space that the
projective matrix functions (`perspective`, `ortho`, etc) are designed to expect. The OpenGL compatibility specifications define the particular layout of this eye space.
Convert scalar and vector types to and from packed formats, saving space at the cost of precision. However, packing a value into a format that it was previously unpacked from is guaranteed to be lossless.
This extension defines an overloaded function, `glm::value_ptr`, which returns a pointer to the memory layout of any GLM vector or matrix (`vec3`, `mat4`, etc.). Matrix types store their values in column-major order. This is useful for uploading data to matrices or for copying data to buffer objects.
*Note: It would be possible to implement [`glVertex3fv`](http://www.opengl.org/sdk/docs/man2/xhtml/glVertex.xml)(glm::vec3(0)) in C++ with the appropriate cast operator that would result as an
implicit cast in this example. However cast operators may produce programs running with unexpected behaviours without build error or any form of notification. *
Measure a function's accuracy given a reference implementation of it. This extension works on floating-point data and provides results in [ULP](http://ljk.imag.fr/membres/Carine.Lucas/TPScilab/JMMuller/ulp-toms.pdf).
OpenGL 3.1 specification has deprecated some features that have been removed from OpenGL 3.2 core profile specification. GLM provides some replacement functions.
The GLSL function 'not' is a keyword in C++. To prevent name collisions and ensure a consistent API, the name `not\_` (note the underscore) is used instead.
GLM supports GLSL precision qualifiers through prefixes instead of qualifiers. For example, GLM exposes \verb|lowp_vec4|, \verb|mediump_vec4| and \verb|highp_vec4| as variations of \verb|vec4|.
Similarly to GLSL, GLM precision qualifiers are used to trade precision of operations in term of [ULPs](http://en.wikipedia.org/wiki/Unit_in_the_last_place) for better performance. By default, all the types use high precision.
Following GLSL conventions is a really strict policy of GLM. It has been designed following the idea that everyone does its own math library with his own conventions. The idea is that brilliant developers (the OpenGL ARB) worked together and agreed to make GLSL. Following GLSL conventions
is a way to find consensus. Moreover, basically when a developer knows GLSL, he knows GLM.
GTX extensions are qualified to be experimental extensions. In GLM this means that these extensions might change from version to version without any restriction. In practice, it doesn’t really change except time to
time. GTC extensions are stabled, tested and perfectly reliable in time. Many GTX extensions extend GTC extensions and provide a way to explore features and implementations and APIs and then are promoted to GTC
extensions. This is fairly the way OpenGL features are developed; through extensions.
The Doxygen generated documentation includes a complete list of all extensions available. Explore this [*API documentation*](http://glm.g-truc.net/html/index.html) to get a complete
NO! Chances are that if using namespace glm; is called, especially in a header file, name collisions will happen as GLM is based on GLSL which uses common tokens for types and functions. Avoiding using namespace
Following the Pareto principle where 20% of the code consumes 80% of the execution time, GLM operates perfectly on the 80% of the code that consumes 20% of the performances. Furthermore, thanks to the lowp,
mediump and highp qualifiers, GLM provides approximations which trade precision for performance. Finally, GLM can automatically produce SIMD optimized code for functions of its implementation.
You should not have any warnings even in `/W4` mode. However, if you expect such level for your code, then you should ask for the same level to the compiler by at least disabling the Visual C++ language extensions
(`/Za`) which generates warnings when used. If these extensions are enabled, then GLM will take advantage of them and the compiler will generate warnings.
GLM functions crashing is the result of a domain error. Such behavior follows the precedent set by C and C++'s standard library. For example, it’s a domain error to pass a null vector (all zeroes) to glm::normalize function, or to pass a negative number into std::sqrt.
GLSL is using radians but GLU is using degrees to express angles. This has caused GLM to use inconsistent units for angles. Starting with GLM 0.9.6, all GLM functions are using radians. For more information, follow
It is highly recommended to [`define NOMINMAX`](http://stackoverflow.com/questions/4913922/possible-problems-with-nominmax-on-visual-c) before including Windows headers to workaround this issue.
### <a name="section7_13"></a> 7.13. Constant expressions support
GLM has some C++ <ahref="http://en.cppreference.com/w/cpp/language/constexpr">constant expressions</a> support. However, GLM automatically detects the use of SIMD instruction sets through compiler arguments to populate its implementation with SIMD intrinsics.
Unfortunately, GCC and Clang doesn't support SIMD instrinsics as constant expressions. To allow constant expressions on all vectors and matrices types, define `GLM_FORCE_PURE` before including GLM headers.
Bug should be reported on Github using the [issue page](https://github.com/g-truc/glm/issues).
A minimal code to reproduce the issue will help.
Additional, bugs can be configuration specific. We can report the configuration by defining `GLM_FORCE_MESSAGES` before including GLM headers then build and copy paste the build messages GLM will output.
```cpp
#define GLM_FORCE_MESSAGES
#include <glm/glm.hpp>
```
An example of build messages generated by GLM:
```
GLM: 0.9.9.1
GLM: C++ 17 with extensions
GLM: GCC compiler detected"
GLM: x86 64 bits with AVX instruction set build target
GLM: Linux platform detected
GLM: GLM_FORCE_SWIZZLE is undefined. swizzling functions or operators are disabled.
GLM: GLM_FORCE_SIZE_T_LENGTH is undefined. .length() returns a glm::length_t, a typedef of int following GLSL.
GLM: GLM_FORCE_UNRESTRICTED_GENTYPE is undefined. Follows strictly GLSL on valid function genTypes.
GLM: GLM_FORCE_DEPTH_ZERO_TO_ONE is undefined. Using negative one to one depth clip space.
GLM: GLM_FORCE_LEFT_HANDED is undefined. Using right handed coordinate system.
```
### <a name="section9_2"></a> 9.2. Contributing to GLM with pull request
This tutorial will show us how to successfully contribute a bug-fix to GLM using GitHub's Pull Request workflow.
We will be typing git commands in the Terminal. Mac and Linux users may have git pre-installed. You can download git from [here](http://git-scm.com/downloads).
The tutorial assumes you have some basic understanding of git concepts - repositories, branches, commits, etc. Explaining it all from scratch is beyond the scope of this tutorial. Some good links to learn git basics are: [Link 1](http://git-scm.com/book/en/Getting-Started-Git-Basics), [Link 2](https://www.atlassian.com/git/tutorial/git-basics)
#### Step 1: Setup our GLM Fork
We will make our changes in our own copy of the GLM sitory. On the GLM GitHub repo and we press the Fork button.
We need to download a copy of our fork to our local machine. In the terminal, type:
```
>>> git clone <our-repository-fork-git-url>
```
This will clone our fork repository into the current folder.
We can find our repository git url on the Github reposotory page. The url looks like this: `https://github.com/<our-username>/<repository-name>.git`
#### Step 2: Synchronizing our fork
We can use the following command to add `upstream` (original project repository) as a remote repository so that we can fetch the latest GLM commits into our branch and keep our forked copy is synchronized.
To synchronize our fork to the latest commit in the GLM repository, we can use the following command:
```
>>> git fetch upstream
```
Then, we can merge the remote master branch to our current branch:
```
>>> git merge upstream/master
```
Now our local copy of our fork has been synchronized. However, the fork's copy is not updated on GitHub's servers yet. To do that, use:
```
>>> git push origin master
```
#### Step 3: Modifying our GLM Fork
Our fork is now setup and we are ready to modify GLM to fix a bug.
It's a good practice to make changes in our fork in a separate branch than the master branch because we can submit only one pull request per branch.
Before creating a new branch, it's best to synchronize our fork and then create a new branch from the latest master branch.
If we are not on the master branch, we should switch to it using:
```
>>> git checkout master
```
To create a new branch called `bugifx`, we use:
```
git branch bugfix
```
Once the code changes for the fix is done, we need to commit the changes:
```
>>> git commit -m "Resolve the issue that caused problem with a specific fix #432"
```
The commit message should be as specific as possible and finished by the bug number in the [GLM GitHub issue page](https://github.com/g-truc/glm/issues)
Finally, we need to push our changes in our branch to our GitHub fork using:
```
>>> git push origin bugfix
```
Some things to keep in mind for a pull request:
* Keep it minimal: Try to make the minimum required changes to fix the issue. If we have added any debugging code, we should remove it.
* A fix at a time: The pull request should deal with one issue at a time only, unless two issue are so interlinked they must be fixed together.
* Write a test: GLM is largely unit tests. Unit tests are in `glm/test` directory. We should also add tests for the fixes we provide to ensure future regression doesn't happen.
* No whitespace changes: Avoid unnecessary formatting or whitespace changes in other parts of the code. Be careful with auto-format options in the code editor which can cause wide scale formatting changes.
* Follow [GLM Code Style](#section9_3) for consistency.
* Tests passes: Make sure GLM build and tests don't fail because of the changes.
#### Step 4: Submitting a Pull Request
We need to submit a pull request from the `bugfix` branch to GLM's master branch.
On the fork github page, we can click on the *Pull Request* button. Then we can describe our pull request. Finally we press *Send Pull Request*.
Please be patient and give them some time to go through it.
The pull request review may suggest additional changes. So we can make those changes in our branch, and push those changes to our fork repository. Our pull request will always include the latest changes in our branch on GitHub, so we don't need to resubmit the pull request.
Once your changes have been accepted, a project maintainer will merge our pull request.
We are grateful to the users for their time and effort in contributing fixes.
### <a name="section9_3"></a> 9.3. Coding style
#### Indentation
Always tabs. Never spaces.
#### Spacing
No space after if. Use if(blah) not if (blah). Example if/else block:
```cpp
if(blah)
{
// yes like this
}
else
{
// something besides
}
```
Single line if blocks:
```cpp
if(blah)
// yes like this
else
// something besides
```
No spaces inside parens:
```cpp
if (blah) // No
if( blah ) // No
if ( blah ) // No
if(blah) // Yes
```
Use spaces before/after commas:
```cpp
someFunction(apple,bear,cat); // No
someFunction(apple, bear, cat); // Yes
```
Use spaces before/after use of `+, -, *, /, %, >>, <<, |, &, ^, ||, &&` operators:
```cpp
vec4 v = a + b;
```
#### Blank lines
One blank line after the function blocks.
#### Comments
Always one space after the // in single line comments
One space before // at the end of a line (that has code as well)
Try to use // comments inside functions, to make it easier to remove a whole block via /* */
#### Cases
```cpp
#define GLM_MY_DEFINE 76
class myClass
{};
myClass const MyClass;
namespace glm{ // glm namespace is for public code
namespace detail // glm::detail namespace is for implementation detail
Leo’s Fortune is a platform adventure game where you hunt down the cunning and mysterious thief that stole your gold. Available on PS4, Xbox One, PC, Mac, iOS and Android.
“I just returned home to find all my gold has been stolen! For some devious purpose, the thief has dropped pieces of my gold like breadcrumbs through the woods.”
A 3D planetary engine for seamless planet rendering from space down to the surface. Can use arbitrary resolution of elevation data, refining it to centimetre resolution using fractal algorithms.
Cinder is a C++ libraryfor programming with aesthetic intent - the sort of development often calledcreative coding. This includes domains like graphics, audio, video, and computational geometry. Cinder is cross-platform, with official support forOS X, Windows, iOS, and WinRT.
Cinder is production-proven, powerful enough to be the primary tool for professionals, but still suitable for learning and experimentation. Cinder is released under the[2-Clause BSD License](http://opensource.org/licenses/BSD-2-Clause).
* [*The OpenGL Samples Pack*](http://www.g-truc.net/project-0026.html#menu), samples that show how to set up all the different new features
* [*Learning Modern 3D Graphics programming*](http://www.arcsynthesis.org/gltut/), a great OpenGL tutorial using GLM by Jason L. McKesson
* [*Morten Nobel-Jørgensen’s*](http://blog.nobel-joergensen.com/2011/04/02/glm-brilliant-math-library-for-opengl/) review and use an [*OpenGL renderer*](https://github.com/mortennobel/RenderE)
* [*Swiftless’ OpenGL tutorial*](http://www.swiftless.com/opengltuts.html) using GLM by Donald Urquhart
* [*Rastergrid*](http://rastergrid.com/blog/), many technical articles with companion programs using GLM by Daniel Rákos\
* [*OpenGL Tutorial*](http://www.opengl-tutorial.org), tutorials for OpenGL 3.1 and later
* [*OpenGL Programming on Wikibooks*](http://en.wikibooks.org/wiki/OpenGL_Programming): For beginners who are discovering OpenGL.
* [*3D Game Engine Programming*](http://3dgep.com/): Learning the latest 3D Game Engine Programming techniques.
* Ashima Arts and Stefan Gustavson for their work on [*webgl-noise*](https://github.com/ashima/webgl-noise) which has been used for GLM noises implementation.
* [*Arthur Winters*](http://athile.net/library/wiki/index.php?title=Athile_Technologies) for the C++11 and Visual C++ swizzle operators implementation and tests.