When <glm/glm.hpp> is included, GLM provides all the GLSL features it implements in C++.
@ -246,7 +246,7 @@ GLM is built with a C++ 11 compiler in which case [static\_assert](http://en.cpp
If neither are detected, GLM will rely on its own implementation of static assert.
---
## 2. Swizzle operators
## 2. Swizzle operators<aname="section2"></a>
A common feature of shader languages like GLSL is the swizzle operators. Those allow selecting multiple components of a vector and change their order. For example, “variable.x”, “variable.xzy” and “variable.zxyy”
form respectively a scalar, a three components vector and a four components vector. With GLSL, swizzle operators can be both R-values and L-values. Finally, vector components can be accessed using “xyzw”,
@ -266,7 +266,7 @@ vec3 C = A.bgr;
GLM supports a subset of this functionality as described in the following sub-sections. Swizzle operators are disabled by default. To enable them GLM\_SWIZZLE must be defined before any inclusion of
<glm/glm.hpp>. Enabling swizzle operators will massively increase the size of compiled files and the compilation time.
### 2.1. Standard C++98 implementation
### 2.1. Standard C++98 implementation<aname="section2_1"></a>
The C++98 implementation exposes the R-value swizzle operators as member functions of vector types.
@ -307,7 +307,7 @@ void foo()
}
```
### 2.2. Anonymous union member implementation
### 2.2. Anonymous union member implementation<aname="section2_2"></a>
Visual C++ supports anonymous structures in union, which is a non-standard language extension, but it enables a very powerful implementation of swizzle operators on Windows supporting both L-value
swizzle operators and a syntax that doesn’t require parentheses in some cases. This implementation is only enabled when the language extension is enabled and GLM\_SWIZZLE is defined.
GLM\_PRECISION\_HIGHP\_UINT: High precision (default)
### 3.2. Compile-time message system {#compile-time-message-system .HeadingB}
### 3.2. Compile-time message system <aname="section3_2"></a>
GLM includes a notification system which can display some information at build time:
@ -421,7 +421,7 @@ only once per project build.
#include<glm/glm.hpp>
```
### 3.3. C++ language detection
### 3.3. C++ language detection<aname="section3_3"></a>
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:
GLM\_FORCE\_CXX14 overrides GLM\_FORCE\_CXX11 and GLM\_FORCE\_CXX11
overrides GLM\_FORCE\_CXX98 defines.
### 3.4. SIMD support
### 3.4. SIMD support<aname="section3_4"></a>
GLM provides some SIMD optimizations based on [compiler intrinsics](https://msdn.microsoft.com/en-us/library/26td21ds.aspx).
These optimizations will be automatically thanks to compiler arguments.
@ -471,7 +471,7 @@ The use of intrinsic functions by GLM implementation can be avoided using the de
Additionally, GLM provides a low level SIMD API in glm/simd directory for users who are really interested in writing fast algorithms.
### 3.5. Force inline
### 3.5. Force inline<aname="section3_5"></a>
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.
@ -480,7 +480,7 @@ To push further the software performance, a programmer can define GLM\_FORCE\_IN
#include<glm/glm.hpp>
```
### 3.6. Vector and matrix static size
### 3.6. Vector and matrix static size<aname="section3_6"></a>
GLSL supports the member function .length() for all vector and matrix types.
By default and following GLSL specifications, vector and matrix default constructors initialize the components to zero. This is a reliable behavior but initialization has a cost and it’s not always necessary.
This behavior can be disable at compilation time by define GLM\_FORCE\_NO\_CTOR\_INIT before any inclusion of <glm/glm.hpp> or other GLM include.
However, defining GLM\_FORCE\_UNRESTRICTED\_GENTYPE is not compatible with GLM\_FORCE\_SWIZZLE and will generate a compilation error if both are defined at the same time.
---
## 4. Stable extensions
## 4. Stable extensions<aname="section4"></a>
GLM extends the core GLSL feature set with extensions. These extensions include: quaternion, transformation, spline, matrix inverse, color spaces, etc.
@ -636,61 +636,61 @@ int foo()
When an extension is included, all the dependent core functionalities and extensions will be included as well.
### 4.1. GLM_GTC_bitfield
### 4.1. GLM_GTC_bitfield<aname="section4_1"></a>
Fast bitfield operations on scalar and vector variables.
<glm/gtc/bitfield.hpp> need to be included to use these features.
Convert scalar and vector types to packed formats. This extension can also unpack packed data to the original format. The use of packing functions will results in precision lost. However, the extension
guarantee that packing a value previously unpacked from the same format will be perform loselessly.
<glm/gtc/packing.hpp> need to be included to use these features.
Handle the interaction between pointers and vector, matrix types.
@ -899,22 +899,22 @@ implicit cast in this example. However cast operators may produce programs runni
<glm/gtc/type\_ptr.hpp> need to be included to use these features.
### 4.20. GLM\_GTC\_ulp
### 4.20. GLM\_GTC\_ulp<aname="section4_20"></a>
Allow the measurement of the accuracy of a function against a reference implementation. This extension works on floating-point data and provides results in [ULP](http://ljk.imag.fr/membres/Carine.Lucas/TPScilab/JMMuller/ulp-toms.pdf).
<glm/gtc/ulp.hpp> need to be included to use these features.
### 4.21. GLM\_GTC\_vec1
### 4.21. GLM\_GTC\_vec1<aname="section4_21"></a>
Add \*vec1 types.
<glm/gtc/vec1.hpp> need to be included to use these features.
### 5.1. GLM replacements for deprecated OpenGL functions
### 5.1. GLM replacements for deprecated OpenGL functions<aname="section5_1"></a>
OpenGL 3.1 specification has deprecated some features that have been removed from OpenGL 3.2 core profile specification. GLM provides some replacement functions.
@ -1061,7 +1061,7 @@ From GLM\_GTC\_matrix\_transform extension:
From GLM\_GTC\_matrix\_transform extension:
<glm/gtc/matrix\_transform.hpp>
### 5.2. GLM replacements for GLU functions
### 5.2. GLM replacements for GLU functions<aname="section5_2"></a>
***gluLookAt: ***
@ -1197,15 +1197,15 @@ From GLM\_GTC\_matrix\_transform extension:
<glm/gtc/matrix\_transform.hpp>
---
## 6. Known issues
## 6. Known issues<aname="section6"></a>
This section reports the divergences of GLM with GLSL.
### 6.1. not function
### 6.1. not function<aname="section6_1"></a>
The GLSL keyword not is also a keyword in C++. To prevent name collisions, ensure cross compiler support and a high API consistency, the GLSL not function has been implemented with the name not\_.
GLM supports GLSL precision qualifiers through prefixes instead of qualifiers. For example, additionally to vec4, GLM exposes lowp\_vec4, mediump\_vec4 and highp\_vec4 types.
@ -1238,42 +1238,42 @@ ivec3 foo(const vec4 & v)
```
---
## 7. FAQ
## 7. FAQ<aname="section7"></a>
### 7.1 Why GLM follows GLSL specification and conventions?
### 7.1 Why GLM follows GLSL specification and conventions?<aname="section7_1"></a>
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.
### 7.2. Does GLM run GLSL program?
### 7.2. Does GLM run GLSL program?<aname="section7_2"></a>
No, GLM is a C++ implementation of a subset of GLSL.
### 7.3. Does a GLSL compiler build GLM codes?
### 7.3. Does a GLSL compiler build GLM codes?<aname="section7_3"></a>
No, this is not what GLM attends to do.
### 7.4. Should I use ‘GTX’ extensions?
### 7.4. Should I use ‘GTX’ extensions?<aname="section7_4"></a>
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.
### 7.5. Where can I ask my questions?
### 7.5. Where can I ask my questions?<aname="section7_5"></a>
A good place is [stackoverflow](http://stackoverflow.com/search?q=GLM) using the GLM tag.
### 7.6. Where can I find the documentation of extensions?
### 7.6. Where can I find the documentation of extensions?<aname="section7_6"></a>
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
view of all GLM capabilities!
### 7.7. Should I use ‘using namespace glm;’?
### 7.7. Should I use ‘using namespace glm;’?<aname="section7_7"></a>
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
glm; will a higher compatibility with third party library and SDKs.
### 7.8. Is GLM fast?
### 7.8. Is GLM fast?<aname="section7_8"></a>
GLM is mainly designed to be convenient and that's why it is written against the GLSL specification.
@ -1282,26 +1282,26 @@ mediump and highp qualifiers, GLM provides approximations which trade precision
However, on performance critical code paths, we should expect that dedicated algorithms should be written to reach peak performance.
### 7.9. When I build with Visual C++ with /W4 warning level, I have warnings...
### 7.9. When I build with Visual C++ with /W4 warning level, I have warnings...<aname="section7_9"></a>
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.
### 7.10. Why some GLM functions can crash because of division by zero?
### 7.10. Why some GLM functions can crash because of division by zero?<aname="section7_10"></a>
GLM functions crashing is the result of a domain error that follows the precedent given by C and C++ libraries. For example, it’s a domain error to pass a null vector to glm::normalize function.
### 7.11. What unit for angles is used in GLM?
### 7.11. What unit for angles is used in GLM?<aname="section7_11"></a>
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
the [link](http://www.g-truc.net/post-0693.html#menu).
---
## 8. Code samples
## 8. Code samples<aname="section8"></a>
This series of samples only shows various GLM features without consideration of any sort.
### 8.1. Compute a triangle normal
### 8.1. Compute a triangle normal<aname="section8_1"></a>