# error "GLM: GTX_associated_min_max is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_bit is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_closest_point is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_color_space is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_color_space_YCoCg is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_common is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_compatibility is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_component_wise is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_dual_quaternion is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_euler_angles is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_extend is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_extented_min_max is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_fast_exponential is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_fast_square_root is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_fast_trigonometry is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_gradient_paint is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_handed_coordinate_space is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_hash is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_integer is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_closest_point is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_io is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_log_base is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_cross_product is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_decompose is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_interpolation is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_major_storage is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_operation is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_query is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_matrix_transform_2d is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_mixed_product is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_norm is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_normal is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_normalize_dot is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_number_precision is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_optimum_pow is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_orthonormalize is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_perpendicular is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_polar_coordinates is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_projection is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_quaternion is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_range is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if !GLM_HAS_RANGE_FOR
# error "GLM_GTX_range requires C++11 suppport or 'range for'"
# error "GLM: GLM_GTX_raw_data is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_rotate_normalized_axis is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_rotate_vector is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_scalar_multiplication is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_extend is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_spline is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_std_based_type is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_string_cast is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
#endif
#if(GLM_COMPILER & GLM_COMPILER_CUDA)
# error "GLM_GTX_string_cast is not supported on CUDA compiler"
# error "GLM: GLM_GTX_transform is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_transform2 is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_type_aligned is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_type_trait is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
/// @brief Functions to perform swizzle operation.
///
/// <glm/gtx/vec_swizzle.hpp> need to be included to use these functionalities.
#pragma once
#include<glm/glm.hpp>
#include"../glm.hpp"
#ifndef GLM_ENABLE_EXPERIMENTAL
# error "GLM: GLM_GTX_vec_swizzle is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_vector_angle is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_vector_query is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
# error "GLM: GLM_GTX_wrap is an experimetal extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
GLM is a header-only library, and thus does not need to be compiled. To use GLM, merely include the `<glm/glm.hpp>` header, which provides GLSL's mathematics functionality.
@ -167,8 +167,7 @@ Core GLM features can be included using individual headers to allow faster user
#include<glm/trigonometric.hpp> // all the GLSL trigonometric functions
#include<glm/vector_relational.hpp> // all the GLSL vector relational functions
GLM makes heavy use of C++ templates, which may significantly increase the compile time for projects that use GLM. Hence, source files should only include the GLM headers they actually use.
@ -182,7 +181,8 @@ To further reduce compilation time, include `<glm/fwd.hpp>`, which provides forw
The `<glm/glm.hpp>` header provides all standard GLSL features.
GLM does not depend on external libraries or external headers such as `<gl.h>`, [`<glcorearb.h>`](http://www.opengl.org/registry/api/GL/glcorearb.h), `<gl3.h>`, `<glu.h>`, or `<windows.h>`. However, if `<boost/static_assert.hpp>` is included, then [`Boost.StaticAssert`](http://www.boost.org/doc/libs/release/libs/static_assert) will be used to provide compile-time errors. Otherwise, if using a C++11 compiler, the standard `static_assert` will be used instead. If neither is available, GLM will use its own implementation of `static_assert`.
---
## 2. Swizzle operators <aname="section2"></a>
## <aname="section2"></a> 2. Swizzle operators
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”,
@ -232,7 +232,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 <aname="section2_1"></a>
### <aname="section2_1"></a> 2.1. Standard C++98 implementation
The C++98 implementation exposes the R-value swizzle operators as member functions of vector types.
@ -273,7 +273,7 @@ void foo()
}
```
### 2.2. Anonymous union member implementation <aname="section2_2"></a>
### <aname="section2_2"></a> 2.2. Anonymous union member implementation
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 <aname="section3_2"></a>
### <aname="section3_2"></a> 3.2. Compile-time message system
GLM includes a notification system which can display some information at build time:
@ -387,7 +387,7 @@ only once per project build.
#include<glm/glm.hpp>
```
### 3.3. C++ language detection <aname="section3_3"></a>
### <aname="section3_3"></a> 3.3. C++ language detection
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 <aname="section3_4"></a>
### <aname="section3_4"></a> 3.4. SIMD support
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.
@ -437,7 +437,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 <aname="section3_5"></a>
### <aname="section3_5"></a> 3.5. Force inline
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.
@ -446,7 +446,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 <aname="section3_6"></a>
### <aname="section3_6"></a> 3.6. Vector and matrix static size
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 <aname="section4"></a>
## <aname="section4"></a> 4. Stable extensions
GLM extends the core GLSL feature set with extensions. These extensions include: quaternion, transformation, spline, matrix inverse, color spaces, etc.
@ -602,61 +602,61 @@ int foo()
When an extension is included, all the dependent core functionalities and extensions will be included as well.
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.
<glm/gtc/packing.hpp> need to be included to use these features.
Facilitate interactions between pointers to basic types (e.g. float*) and GLM types (e.g. mat4).
@ -875,22 +875,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 <aname="section4_20"></a>
### <aname="section4_20"></a> 4.20. GLM\_GTC\_ulp
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).
<glm/gtc/ulp.hpp> need to be included to use these features.
### 5.1. GLM replacements for deprecated OpenGL functions <aname="section5_1"></a>
### <aname="section5_1"></a> 5.1. GLM replacements for deprecated OpenGL functions
OpenGL 3.1 specification has deprecated some features that have been removed from OpenGL 3.2 core profile specification. GLM provides some replacement functions.
From GLM\_GTC\_matrix\_transform extension: <glm/gtc/matrix\_transform.hpp>
---
## 6. Known issues <aname="section6"></a>
## <aname="section6"></a> 6. Known issues
This section reports GLSL features that GLM can't accurately emulate due to language restrictions.
### 6.1. not function <aname="section6_1"></a>
### <aname="section6_1"></a> 6.1. not function
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.
### 6.2. Precision qualifiers support <aname="section6_2"></a>
### <aname="section6_2"></a> 6.2. Precision qualifiers support
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|.
@ -1075,42 +1075,44 @@ ivec3 foo(const vec4 & v)
The syntax for default precision specifications in GLM differs from that in GLSL; for more information, see section Default Precision <aname="section3_1"></a>.
---
## 7. FAQ <aname="section7"></a>
## <aname="section7"></a> 7. FAQ
### 7.1 Why GLM follows GLSL specification and conventions? <aname="section7_1"></a>
### <aname="section7_1"></a> 7.1 Why GLM follows GLSL specification and conventions?
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? <aname="section7_2"></a>
### <aname="section7_2"></a> 7.2. Does GLM run GLSL program?
No, GLM is a C++ implementation of a subset of GLSL.
### 7.3. Does a GLSL compiler build GLM codes? <aname="section7_3"></a>
### <aname="section7_3"></a> 7.3. Does a GLSL compiler build GLM codes?
No, this is not what GLM attends to do.
### 7.4. Should I use ‘GTX’ extensions? <aname="section7_4"></a>
### <aname="section7_4"></a> 7.4. Should I use ‘GTX’ extensions?
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? <aname="section7_5"></a>
Stating with GLM 0.9.9, to use experimental extensions, an application but define GLM_ENABLE_EXPERIMENTAL.
### <aname="section7_5"></a> 7.5. Where can I ask my questions?
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? <aname="section7_6"></a>
### <aname="section7_6"></a> 7.6. Where can I find the documentation of 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
view of all GLM capabilities!
### 7.7. Should I use ‘using namespace glm;’? <aname="section7_7"></a>
### <aname="section7_7"></a> 7.7. Should I use ‘using namespace glm;’?
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? <aname="section7_8"></a>
### <aname="section7_8"></a> 7.8. Is GLM fast?
GLM is mainly designed to be convenient and that's why it is written against the GLSL specification.
@ -1119,26 +1121,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... <aname="section7_9"></a>
### <aname="section7_9"></a> 7.9. When I build with Visual C++ with /W4 warning level, I have warnings...
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? <aname="section7_10"></a>
### <aname="section7_10"></a> 7.10. Why some GLM functions can crash because of division by zero?
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.
### 7.11. What unit for angles is used in GLM? <aname="section7_11"></a>
### <aname="section7_11"></a> 7.11. What unit for angles is used in GLM?
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 <aname="section8"></a>
## <aname="section8"></a> 8. Code samples
This series of samples only shows various GLM features without consideration of any sort.
### 8.1. Compute a triangle normal <aname="section8_1"></a>
### <aname="section8_1"></a> 8.1. Compute a triangle normal
@ -1322,11 +1324,11 @@ A 3D planetary engine for seamless planet rendering from space down to the surfa

***Falcor***
[***Falcor***](https://github.com/NVIDIA/Falcor)
Real-time rendering research framework by NVIDIA.
***Cinder***
[***Cinder***](https://libcinder.org/)
Cinder is a free and open source library for professional-quality creative coding in C++.
@ -1346,10 +1348,16 @@ Simple, easy-to-follow examples with GLSL source code, as well as a basic descri

[***LibreOffice***](https://www.libreoffice.org/)
LibreOffice includes several applications that make it the most powerful Free and Open Source office suite on the market.
[***Are you using GLM in a project?***](mailto:glm@g-truc.net)
### 9.4. OpenGL tutorials using GLM <aname="section9_4"></a>
### <aname="section9_4"></a> 9.4. Tutorials using GLM
* [Sascha Willems' Vulkan examples](https://github.com/SaschaWillems/Vulkan), Examples and demos for the new Vulkan API
* [VKTS](https://github.com/McNopper/Vulkan) Vulkan examples using VulKan ToolS (VKTS)
* [*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)
@ -1364,25 +1372,26 @@ Simple, easy-to-follow examples with GLSL source code, as well as a basic descri