2015-11-23 19:09:35 +00:00
\documentclass { scrartcl}
% Packages
% ---
\usepackage [export] { adjustbox}
\usepackage [utf8] { inputenc} % Unicode support (Umlauts etc.)
\usepackage { amsmath}
\usepackage { cprotect} % Allow verbatim text in macro arguments
\usepackage { dirtytalk} % For proper quotations
\usepackage { graphicx} % Add pictures to your document
\usepackage { hyperref} % Add a link to your document
\usepackage { minted} % Source code formatting and highlighting
\usepackage { wrapfig}
\usepackage { xcolor}
\usepackage { lmodern}
\usepackage [T1] { fontenc}
\numberwithin { figure} { subsection}
2015-11-23 19:13:07 +00:00
\graphicspath { { img/} }
2015-11-23 19:09:35 +00:00
\setlength { \parindent } { 0em}
\setlength { \parskip } { 1em}
\definecolor { beige} { rgb} { 0.95,0.95,0.92}
\hypersetup {
pdfborderstyle={ /S/U/W 1} ,
pdfauthor=Christophe Riccio,
pdftitle=GLM Manual
}
\usemintedstyle { borland}
\newminted { cpp} { linenos, bgcolor=beige}
\newminted { glsl} { linenos, bgcolor=beige}
2015-11-27 21:43:09 +00:00
2015-11-23 19:09:35 +00:00
\begin { document}
2015-11-27 21:43:09 +00:00
\newcommand { \glmheader } [1]{ \href { https://github.com/g-truc/glm/tree/master/glm/#1.hpp} { \texttt { <glm/#1.hpp>} } }
2015-12-03 18:42:23 +00:00
\newcommand { \glmemail } [1]{ \href { mailto://glm@g-truc.net} { #1} }
\newcommand { \glufunction } [1]{ \href { https://www.opengl.org/sdk/docs/man2/xhtml/#1.xml} { \texttt { #1} } }
\newcommand { \glfunction } [2]{ \href { http://docs.gl/gl#1/#2} { \texttt { #2} } }
2015-11-27 21:43:09 +00:00
2015-11-23 19:09:35 +00:00
% Set up the maketitle command
\author { Christophe Riccio}
\subtitle { Version 0.9.7}
2015-12-03 19:01:35 +00:00
\titlehead { \centering \includegraphics [width=6cm] { logo} }
2015-11-23 19:09:35 +00:00
\title { GLM Manual}
\date { \today { } } % You can remove \today{} and type a date manually
\maketitle { } % Generates title
\pagebreak { }
\section * { Licensing}
2015-11-27 21:32:50 +00:00
\addcontentsline { toc} { section} { Licensing}
2015-11-23 19:09:35 +00:00
\subsection * { \hypertarget { happybunny} { The Happy Bunny License (Modified MIT License)} }
2015-11-27 21:32:50 +00:00
\addcontentsline { toc} { subsection} { The Happy Bunny License (Modified MIT License)}
2015-11-23 19:09:35 +00:00
\copyright { } 2008 - 2015 G-Truc Creation
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \say { Software} ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Restrictions: By making use of the Software for military purposes, you choose to make a Bunny unhappy.
THE SOFTWARE IS PROVIDED \say { AS IS} , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2015-12-03 19:01:35 +00:00
\begin { center}
\includegraphics [width=0.8\textwidth] { duck-large1}
\end { center}
2015-11-23 19:09:35 +00:00
\pagebreak { }
\subsection * { \hypertarget { mit} { The MIT License} }
2015-11-27 21:32:50 +00:00
\addcontentsline { toc} { subsection} { The MIT License}
2015-11-23 19:09:35 +00:00
\copyright { } 2008 - 2015 G-Truc Creation
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \say { Software} ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED \say { AS IS} , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\begin { center}
\includegraphics [width=\textwidth] { duck-large2}
\end { center}
\pagebreak { }
\tableofcontents { }
\pagebreak { }
\section * { Introduction}
2015-11-27 21:32:50 +00:00
\addcontentsline { toc} { section} { Introduction}
2015-11-23 19:09:35 +00:00
2015-11-27 21:36:48 +00:00
OpenGL Mathematics (GLM) is a C++ mathematics library based on the \href { https://www.opengl.org/documentation/glsl/} { OpenGL Shading Language} (GLSL) specification.
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:46 +00:00
GLM provides classes and functions to mimic the conventions and functionality provided by GLSL. An extension system (inspired by OpenGL's) also provides extra capabilities including (but not limited to) matrix transformations, quaternions, data packing, random numbers, and noise.
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:46 +00:00
GLM works perfectly with \href { http://www.opengl.org} { OpenGL} , but is also well-suited for use with any project that demands a simple (yet flexible) mathematics framework such as software rendering (ray-tracing/rasterisation), image processing, and physics simulation.
2015-11-23 19:09:35 +00:00
2015-11-27 21:36:48 +00:00
GLM is written in C++98, but can take advantage of C++11 where support exists. GLM is platform independent, has no dependencies, and supports the following compilers:
2015-11-23 19:09:35 +00:00
\begin { itemize}
\item \href { https://developer.apple.com/Library/mac/documentation/CompilerTools/Conceptual/LLVMCompilerOverview/index.html} { Apple Clang} 4.0 and higher
\item \href { http://gcc.gnu.org/} { GCC} 4.2 and higher
\item \href { https://software.intel.com/en-us/intel-compilers} { Intel C++ Composer} XE 2013 and higher
\item \href { http://llvm.org/} { LLVM} 3.0 and higher
\item \href { http://www.visualstudio.com/} { Visual C++} 2010 and higher
\item \href { https://developer.nvidia.com/about-cuda} { CUDA} 4.0 and higher (experimental)
\item Any conforming C++98 or C++11 compiler
\end { itemize}
2015-12-03 18:42:46 +00:00
The source code and the documentation (including this manual) are licensed under both the \hyperlink { happybunny} { Happy Bunny License (Modified MIT)} and the \hyperlink { mit} { MIT License} .
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:23 +00:00
Feedback, bug reports, feature requests, and acts upon thereof are highly appreciated. The author may be contacted at \glmemail { glm@g-truc.net} .
2015-11-23 19:09:35 +00:00
\section { Getting Started}
\subsection { Setup}
2015-12-03 18:42:46 +00:00
GLM is a header-only library, and thus does not need to be compiled. To use GLM, merely include the \glmheader { glm} header, which provides GLSL's mathematics functionality.
2015-11-23 19:09:35 +00:00
\begin { itemize}
2015-11-27 21:43:09 +00:00
\item \glmheader { vec2} : \verb |vec2|, \verb |bvec2|, \verb |dvec2|, \verb |ivec2| and \verb |uvec2|
\item \glmheader { vec3} : \verb |vec3|, \verb |bvec3|, \verb |dvec3|, \verb |ivec3| and \verb |uvec3|
\item \glmheader { vec4} : \verb |vec4|, \verb |bvec4|, \verb |dvec4|, \verb |ivec4| and \verb |uvec4|
\item \glmheader { mat2x2} : \verb |mat2|, \verb |dmat2|
\item \glmheader { mat2x3} : \verb |mat2x3|, \verb |dmat2x3|
\item \glmheader { mat2x4} : \verb |mat2x4|, \verb |dmat2x4|
\item \glmheader { mat3x2} : \verb |mat3x2|, \verb |dmat3x2|
\item \glmheader { mat3x3} : \verb |mat3|, \verb |dmat3|
\item \glmheader { mat3x4} : \verb |mat3x4|, \verb |dmat3x4|
\item \glmheader { mat4x2} : \verb |mat4x2|, \verb |dmat4x2|
\item \glmheader { mat4x3} : \verb |mat4x3|, \verb |dmat4x3|
\item \glmheader { mat4x4} : \verb |mat4|, \verb |dmat4|
\item \glmheader { common} : all the GLSL common functions
\item \glmheader { exponential} : all the GLSL exponential functions
\item \glmheader { geometry} : all the GLSL geometry functions
\item \glmheader { integer} : all the GLSL integer functions
\item \glmheader { matrix} : all the GLSL matrix functions
\item \glmheader { packing} : all the GLSL packing functions
\item \glmheader { trigonometric} : all the GLSL trigonometric functions
\item \glmheader { vector\_ relational} : all the GLSL vector relational functions
2015-11-23 19:09:35 +00:00
\end { itemize}
2015-11-27 22:30:32 +00:00
\subsection { Faster Compilation}
% TODO: Benchmark explicit extern template instantiations and write something about them if beneficial http://en.cppreference.com/w/cpp/language/class_template
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.
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:46 +00:00
To further reduce compilation time, include \glmheader { fwd} , which provides forward declarations of all types.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
2015-12-03 18:42:46 +00:00
// Header file (forward declarations only)
2015-11-23 19:09:35 +00:00
#include <glm/fwd.hpp>
\end { cppcode}
\begin { cppcode}
2015-12-03 18:42:46 +00:00
// Source file (actual types included)
2015-11-23 19:09:35 +00:00
#include <glm/glm.hpp>
\end { cppcode}
\subsection { Example Usage}
\begin { cppcode}
// Include GLM core features
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
// Include GLM extensions
#include <glm/gtc/matrix_ transform.hpp>
using glm::vec2;
using glm::vec3;
using glm::mat4;
mat4 transform(
vec2 const & Orientation,
vec3 const & Translate,
vec2 const & Up)
{
mat4 Projection = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f);
mat4 ViewTranslate = glm::translate(mat4(1.0f), Translate);
mat4 ViewRotateX = glm::rotate(ViewTranslate, Orientation.y, Up);
mat4 View = glm::rotate(ViewRotateX, Orientation.x, Up);
mat4 Model = mat4(1.0f);
return Projection * View * Model;
}
\end { cppcode}
\subsection { Dependencies}
2015-11-27 22:31:05 +00:00
The \glmheader { glm} header provides all standard GLSL features.
2015-11-23 19:09:35 +00:00
2015-11-27 22:31:05 +00:00
GLM does not depend on external libraries or external headers such as \verb |gl.h|, \href { http://www.opengl.org/registry/api/GL/glcorearb.h} { \texttt { glcorearb.h} } , \verb |gl3.h|, \verb |glu.h| or \verb |windows.h|. However, if \verb |<boost/static_ assert.hpp>| is included, then \href { http://www.boost.org/doc/libs/release/libs/static_ assert/} { \texttt { Boost.StaticAssert} } will be used to provide compile-time errors. Otherwise, if using a C++11 compiler, the standard \verb |static_ assert| will be used instead. If neither is available, GLM will use its own implementation of \verb |static_ assert|.
2015-11-23 19:09:35 +00:00
\newpage { }
2015-12-03 18:43:20 +00:00
\section { Swizzling}
2015-11-23 19:09:35 +00:00
2015-12-03 18:43:20 +00:00
Shader languages like GLSL often feature so-called swizzle expression, which may be used to freely select and arrange a vector's components. For example, \verb |variable.x|, \verb |variable.xzy| and \verb |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 \verb |xyzw| (usually for positions), \verb |rgba| (usually for colors), or \verb |stpq| (usually for texture coordinates).
2015-11-23 19:09:35 +00:00
\begin { glslcode}
vec4 A;
vec2 B;
B.yx = A.wy;
B = A.xx;
vec3 C = A.bgr;
vec3 D = B.rsz; // Invalid, won't compile
\end { glslcode}
2015-12-03 18:43:20 +00:00
GLM optionally supports some of this functionality via the methods described in the following sections. Swizzling can be enabled by defining \verb |GLM_ SWIZZLE| before including any GLM header files, or as part of your project's build process.
2015-11-23 19:09:35 +00:00
2015-12-03 18:43:20 +00:00
\emph { Note that enabling swizzle expressions will massively increase the size of your binaries and the time it takes to compile them!}
2015-11-23 19:09:35 +00:00
\subsection { Default C++98 Implementation}
2015-12-03 18:43:20 +00:00
When compiling GLM as C++98, R-value swizzle expressions are simulated through member functions of each vector type.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ SWIZZLE // Or define when building (e.g. -DGLM_ SWIZZLE)
#include <glm/glm.hpp>
void foo()
{
glm::vec4 ColorRGBA(1.0f, 0.5f, 0.0f, 1.0f);
glm::vec3 ColorBGR = ColorRGBA.bgr();
glm::vec3 PositionA(1.0f, 0.5f, 0.0f, 1.0f);
glm::vec3 PositionB = PositionXYZ.xyz() * 2.0f;
glm::vec2 TexcoordST(1.0f, 0.5f);
glm::vec4 TexcoordSTPQ = TexcoordST.stst();
}
\end { cppcode}
Swizzle operators return a \textbf { copy} of the component values, and thus \textbf { can't} be used as L-values to change a vector's values.
\begin { cppcode}
#define GLM_ SWIZZLE
#include <glm/glm.hpp>
void foo()
{
glm::vec3 A(1.0f, 0.5f, 0.0f);
2015-11-27 22:31:52 +00:00
// No compiler error, but A is not modified.
// An anonymous copy is being modified (and then discarded).
2015-11-23 19:09:35 +00:00
A.bgr() = glm::vec3(2.0f, 1.5f, 1.0f); // A is not modified!
}
\end { cppcode}
\subsection { Anonymous Union Member Implementation}
2015-12-03 18:43:20 +00:00
Visual C++ supports, as a \emph { non-standard language extension} , anonymous \verb |struct|s in \verb |union|s. This enables a very powerful implementation of swizzle expressions on Windows, which both allows L-value swizzle operators and makes the syntax for it closer to GLSL's. You must enable this language extension in a supported compiler and define \verb |GLM_ SWIZZLE| to use this implementation of swizzling.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ SWIZZLE
#include <glm/glm.hpp>
// Only guaranteed to work with Visual C++!
// Some compilers that support Microsoft extensions may compile this.
void foo()
{
glm::vec4 ColorRGBA(1.0f, 0.5f, 0.0f, 1.0f);
// l-value:
glm::vec4 ColorBGRA = ColorRGBA.bgra;
// r-value:
ColorRGBA.bgra = ColorRGBA;
// Both l-value and r-value
ColorRGBA.bgra = ColorRGBA.rgba;
}
\end { cppcode}
2015-12-03 18:43:20 +00:00
This versions returns implementation-specific objects that \emph { implicitly convert} to their respective vector types. Unfortunately, these extra types can't be directly used by GLM functions; you must instead convert a swizzle-made \say { vector} to a conventional vector type or call the swizzle object's \verb |operator()|.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ SWIZZLE
#include <glm/glm.hpp>
using glm::vec4;
void foo()
{
vec4 Color(1.0f, 0.5f, 0.0f, 1.0f);
// Generates compiler errors. Color.rgba is not a vector type.
vec4 ClampedA = glm::clamp(Color.rgba, 0.f, 1.f); // ERROR
2015-11-27 22:31:52 +00:00
// Explicit conversion through a constructor
2015-11-23 19:09:35 +00:00
vec4 ClampedB = glm::clamp(vec4(Color.rgba), 0.f, 1.f); // OK
2015-11-27 22:31:52 +00:00
// Explicit conversion through operator()
2015-11-23 19:09:35 +00:00
vec4 ClampedC = glm::clamp(Color.rgba(), 0.f, 1.f); // OK
}
\end { cppcode}
\newpage { }
\section { Preprocessor Options}
\subsection { Default Precision}
2015-12-03 18:43:54 +00:00
\label { Default Precision}
C++ does not provide a way to implement GLSL default precision selection (as defined in GLSL 4.10 specification section 4.5.3) with GLSL-like syntax.
2015-11-23 19:09:35 +00:00
\begin { glslcode}
precision mediump int;
precision highp float;
\end { glslcode}
2015-12-03 18:43:54 +00:00
To set the default precision of a given arithmetic type, use any of the following defines:
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ PRECISION_ MEDIUMP_ INT
#define GLM_ PRECISION_ HIGHP_ FLOAT
// Or, again, as part of your build process
#include <glm/glm.hpp>
\end { cppcode}
Available defines for floating point types (\verb |glm::vec|*, \verb |glm::mat|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ FLOAT|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ FLOAT|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ FLOAT|: High precision (default)
\end { itemize}
2015-11-27 22:32:20 +00:00
Available defines for double-precision floating point types (\verb |glm::dvec|*, \verb |glm::dmat|*):
2015-11-23 19:09:35 +00:00
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ DOUBLE|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ DOUBLE|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ DOUBLE|: High precision (default)
\end { itemize}
Available defines for signed integer types (\verb |glm::ivec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ INT|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ INT|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ INT|: High precision (default)
\end { itemize}
Available defines for unsigned integer types (\verb |glm::uvec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ UINT|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ UINT|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ UINT|: High precision (default)
\end { itemize}
\subsection { Compile-Time Messages}
2015-11-27 22:32:47 +00:00
GLM can optionally display the following at compile-time:
2015-11-23 19:09:35 +00:00
\begin { itemize}
\item Platform: Windows, Linux, Native Client, QNX, etc.
\item Compiler: Visual C++, Clang, GCC, ICC, etc.
\item Build model: 32-bit or 64-bit
\item C++ version: C++98, C++11, MS extensions, etc.
\item Architecture: x86, SSE, AVX, etc.
\item Included extensions
\end { itemize}
2015-11-27 21:43:09 +00:00
To enable compile-time messaging, define \verb |GLM_ MESSAGES| before any inclusion of \glmheader { glm} . The messages are generated once per build, assuming your compiler supports \verb |#pragma message|.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ MESSAGES // Or as part of your build
#include <glm/glm.hpp>
\end { cppcode}
\subsection { C++ Language Detection}
2015-12-03 18:43:54 +00:00
GLM may implement certain features that require the presence of a minimum C++ standard. You can mandate compatibility with particular revisions of C++ by defining \verb |GLM_ FORCE_ CXX|** before any inclusion of \glmheader { glm} (where ** is one of \verb |98|, \verb |03|, \verb |11|, and \verb |14|).
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ FORCE_ CXX98
#include <glm/glm.hpp>
// Nothing that was introduced after 1998 will be used in GLM.
\end { cppcode}
\begin { cppcode}
#define GLM_ FORCE_ CXX14
#include <glm/glm.hpp>
// Live life on the bleeding edge; go big or go home!
\end { cppcode}
2015-11-27 22:33:01 +00:00
Later standards will override earlier ones, like so:
2015-11-23 19:09:35 +00:00
\verb |GLM_ FORCE_ CXX14| $ > $ \verb |GLM_ FORCE_ CXX11| $ > $ \verb |GLM_ FORCE_ CXX03| $ > $ \verb |GLM_ FORCE_ CXX98|
\subsection { SIMD Support}
2015-11-27 22:33:37 +00:00
GLM provides some SIMD (Single instruction, multiple data) optimizations based on compiler intrinsics, which will be automatically utilized based on compiler's arguments. For example, if a program is compiled in Visual C++ with \verb |/arch:AVX| set, certain GLM functionality will use AVX instructions.
2015-11-23 19:09:35 +00:00
2015-11-27 22:33:37 +00:00
In addition, GLM provides specialized \verb |vec4|, \verb |quat|, and \verb |mat4| implementations through the \verb |GLM_ GTX_ simd_ vec4|, \verb |GLM_ GTX_ simd_ quat|, and \verb |GLM_ GTX_ simd_ mat4| extensions.
2015-11-23 19:09:35 +00:00
2015-12-03 18:43:54 +00:00
You can force GLM to use a particular set of intrinsics with the following defines: \verb |GLM_ FORCE_ SSE2|, \verb |GLM_ FORCE_ SSE3|, \verb |GLM_ FORCE_ SSE4|, \verb |GLM_ FORCE_ AVX| or \verb |GLM_ FORCE_ AVX2|.
2015-11-23 19:09:35 +00:00
2015-12-03 18:43:54 +00:00
You may also disable intrinsics entirely by defining \verb |GLM_ FORCE_ PURE| before any inclusion of \glmheader { glm} . If \verb |GLM_ FORCE_ PURE| is defined, then including any SIMD extension will generate a compiler error.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ FORCE_ PURE
#include <glm/glm.hpp>
// GLM code without any form of intrinsics.
\end { cppcode}
Useful as \verb |GLM_ FORCE_ PURE| is, I suggest you enforce this with compiler arguments instead.
\begin { cppcode}
#define GLM_ FORCE_ AVX2
#include <glm/glm.hpp>
2015-11-27 22:33:37 +00:00
// Will only compile if AVX2 intrinsics are supported.
2015-11-23 19:09:35 +00:00
\end { cppcode}
\subsection { Force Inline}
2015-12-03 18:43:54 +00:00
To gain a bit of performance, you can define \verb |GLM_ FORCE_ INLINE| before any inclusion of \glmheader { glm} to force the compiler to inline GLM code.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#define GLM_ FORCE_ INLINE
#include <glm/glm.hpp>
\end { cppcode}
2015-11-27 22:34:38 +00:00
\subsection { Compile-Time Type Info}
2015-11-23 19:09:35 +00:00
The member function \verb |length()| returns the dimensionality (number of components) of any GLSL matrix or vector type.
\begin { cppcode}
#include <glm/glm.hpp>
void foo(vec4 const & v)
{
int Length = v.length(); // returns 4
}
\end { cppcode}
There are two problems with this function.
2015-12-03 18:43:54 +00:00
The first problem is that \verb |length()| returns an \verb |int| (signed) despite typically being used with code that expects a \verb |size_ t| (unsigned). To force a \verb |length()| member function to return a \verb |size_ t|, define \verb |GLM_ FORCE_ SIZE_ T_ LENGTH|.
2015-11-23 19:09:35 +00:00
GLM also defines the \verb |typedef| \verb |glm::length_ t| to identify the returned type of \verb |length()|, regardless of whether \verb |GLM_ FORCE_ SIZE_ T_ LENGTH| is set.
\begin { cppcode}
#define GLM_ FORCE_ SIZE_ T_ LENGTH
#include <glm/glm.hpp>
void foo(vec4 const & v)
{
glm::size_ t Length = v.length();
}
\end { cppcode}
2015-12-03 18:43:54 +00:00
The second problem is that \verb |length()| shares its name with \verb |glm::length(|*\verb |vec|*\verb | const & v)|, which is used to return a vector's Euclidean length. Developers familiar with other vector math libraries may be used to their equivalent of \verb |glm::length(|*\verb |vec|*\verb | const & v)| being defined as a member function, and may thus ask for a vector's dimensionality when they intend to ask for its Euclidean length.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#include <glm/glm.hpp>
void foo(glm::vec3 const & target)
{
float distance = v.length(); // Always returns 3. Oops!
}
\end { cppcode}
To resolve this, define \verb |GLM_ FORCE_ SIZE_ FUNC| to use \verb |size()| for dimensionality queries.
\begin { cppcode}
#define GLM_ FORCE_ SIZE_ FUNC
#include <glm/glm.hpp>
void foo(glm::vec4 const & v)
{
glm::size_ t Size = v.size(); // Always returns 4
}
\end { cppcode}
2015-11-27 22:34:38 +00:00
As of GLM 0.9.7.0, GLM also provides the \verb |GLM_ META_ PROG_ HELPERS|, which enables \verb |static| members that provide information about vector, matrix, and quaternion types at compile time in a manner suitable for template metaprogramming.
2015-11-23 19:09:35 +00:00
2015-11-27 22:34:38 +00:00
\begin { cppcode}
#define GLM_ META_ PROG_ HELPERS
#include <glm/glm.hpp>
template<typename VecT>
void foo(VecT const & v)
{
static_ assert(VecT::components < 4, "4D doesn't make sense!");
glm::vec2<VecT::value_ type, VecT::prec> something;
// vec2 with the same component type and precision as VecT
}
template<typename MatT>
void bar(MatT const & m)
{
static_ assert(MatT::rows == MatT::cols, "Square matrices only!");
}
\end { cppcode}
2015-11-23 19:09:35 +00:00
2015-11-27 22:34:38 +00:00
\subsection { Disabling Default Initialization}
2015-11-27 22:35:11 +00:00
By default, the nullary (zero-argument) constructors of vectors and matrices initialize their components to zero, as demanded by the GLSL specification. Such behavior is reliable and convenient, but sometimes unnecessary. Disable it at compile time by defining \verb |GLM_ FORCE_ NO_ CTOR_ INIT|.
2015-11-23 19:09:35 +00:00
GLM's default behavior:
\begin { cppcode}
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v; // v is (0.0f, 0.0f, 0.0f, 0.0f)
}
\end { cppcode}
GLM behavior using \verb |GLM_ FORCE_ NO_ CTOR_ INIT|:
\begin { cppcode}
#define GLM_ FORCE_ NO_ CTOR_ INIT
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v; // v's components are undefined
}
\end { cppcode}
2015-12-03 18:43:54 +00:00
Alternatively, individual variables may be left undefined, like so:
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v(glm::uninitialize); // v's components are undefined
}
\end { cppcode}
\subsection { Requiring Explicit Conversions}
2015-11-27 22:21:29 +00:00
GLSL allows implicit conversions of vector and matrix types (e.g. from \verb |ivec4| to \verb |vec4|).
2015-11-23 19:09:35 +00:00
\begin { glslcode}
ivec4 a;
vec4 b = a; // Implicit conversion, OK
\end { glslcode}
2015-11-27 22:21:29 +00:00
Such behavior isn't always desirable in C++, but in the spirit of GLM's mission it is fully supported.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#include <glm/glm.hpp>
void foo()
{
glm::ivec4 a;
glm::vec4 b(a); // Explicit conversion, OK
glm::vec4 c = a; // Implicit conversion, OK
}
\end { cppcode}
To instead require all conversions between GLM types to be explicit (making implicit conversions a compiler error), define \verb |GLM_ FORCE_ EXPLICIT_ CTOR|.
\begin { cppcode}
#define GLM_ FORCE_ EXPLICIT_ CTOR
#include <glm/glm.hpp>
// This function is the same as above.
void foo()
{
glm::ivec4 a;
glm::vec4 b(a); // Explicit conversion, OK
glm::vec4 c = a; // Implicit conversion, ERROR
}
\end { cppcode}
\section { Stable Extensions}
2015-12-03 18:44:15 +00:00
GLM provides additional functionality on top of GLSL's, including (but not limited to) quaternions, matrix transformations, random number generation, and color space conversion.
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
All extra features are part of the \verb |glm| namespace, and can be enabled by including the relevant header file.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#include <glm/glm.hpp>
#include <glm/gtc/matrix_ transform.hpp>
using glm::vec3;
using glm::vec4;
using glm::mat4;
void foo()
{
vec4 Position = vec4(vec3(0.0f), 1.0f);
mat4 Model = glm::translate(mat4(1.0f), vec3(1.0f));
vec4 Transformed = Model * Position;
}
\end { cppcode}
Descriptions of the most stable extensions follow.
\subsection { \texttt { GLM\_ GTC\_ bitfield} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/bitfield}
2015-11-23 19:09:35 +00:00
Fast bitfield operations on scalar and vector variables.
\subsection { \texttt { GLM\_ GTC\_ color\_ space} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/color\_ space}
2015-11-23 19:09:35 +00:00
2015-11-27 22:35:39 +00:00
Conversion between linear RGB and sRGB color spaces.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ constants} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/constants}
2015-11-23 19:09:35 +00:00
2015-11-27 22:35:39 +00:00
Built-in constants such as $ \pi $ , $ e $ , and $ \phi $ .
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ epsilon} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/epsilon}
2015-11-23 19:09:35 +00:00
2015-11-27 22:35:39 +00:00
Approximate equality comparisons for floating-point numbers, possibly with a user-defined epsilon.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ integer} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/integer}
2015-12-03 18:44:15 +00:00
Integer variants of core GLM functions.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ matrix\_ access} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ access}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Functions to conveniently access the individual rows or columns of a matrix.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ matrix\_ integer} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ integer}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Integer matrix types similar to the core floating-point matrices. Some operations (such as inverse and determinant) are not supported.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ matrix\_ inverse} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ inverse}
2015-12-03 18:44:15 +00:00
Additional matrix inverse functions.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ matrix\_ transform} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Matrix transformation functions that follow the old OpenGL fixed-function conventions. For example, the \verb |lookAt| function generates a transformation matrix that projects world coordinates into eye coordinates suitable for projection matrices (e.g. \verb |perspective|, \verb |ortho|). See the OpenGL compatibility specifications for more information about the layout of these generated matrices.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ noise} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/noise}
2015-11-23 19:09:35 +00:00
Define 2D, 3D and 4D procedural noise functions.
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { simplex1}
\cprotect \caption { \verb |simplex(vec2(x / 16.f, y / 16.f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { simplex2}
\cprotect \caption { \verb |simplex(vec3(x / 16.f, y / 16.f, 0.5f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { simplex3}
\cprotect \caption { \verb |simplex(vec4(x / 16.f, y / 16.f, 0.5f, 0.5f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { perlin1}
\cprotect \caption { \verb |perlin(vec2(x / 16.f, y / 16.f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { perlin2}
\cprotect \caption { \verb |perlin(vec3(x / 16.f, y / 16.f, 0.5f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { perlin3}
\cprotect \caption { \verb |perlin(vec4(x / 16.f, y / 16.f, 0.5f, 0.5f)));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { perlin4}
\cprotect \caption { \verb |perlin(vec2(x / 16.f, y / 16.f), vec2(2.0f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { perlin5}
\cprotect \caption { \verb |perlin(vec3(x / 16.f, y / 16.f, 0.5f), vec3(2.0f));|}
\end { figure}
\begin { figure}
\centering
\includegraphics [width=0.3\textwidth] { perlin6}
\cprotect \caption { \verb |perlin(vec4(x / 16.f, y / 16.f, vec2(0.5f)), vec4(2.0f));|}
\end { figure}
\subsection { \texttt { GLM\_ GTC\_ packing} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/packing}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
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 \textbf { guaranteed} to be lossless.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ quaternion} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/quaternion}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Quaternions and operations upon thereof.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ random} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/random}
2015-12-03 18:44:15 +00:00
Probability distributions in up to four dimensions..
2015-11-23 19:09:35 +00:00
\begin { figure} [h]
\centering
\includegraphics [width=0.5\textwidth] { linearrand}
\cprotect \caption { \verb |vec4(linearRand(vec2(-1), vec2(1)), 0, 1);|}
\end { figure}
\begin { figure} [h]
\centering
\includegraphics [width=0.5\textwidth] { circularrand}
\cprotect \caption { \verb |vec4(circularRand(1.0f), 0, 1);|}
\end { figure}
\begin { figure} [h]
\centering
\includegraphics [width=0.5\textwidth] { sphericalrand}
\cprotect \caption { \verb |vec4(sphericalRand(1.0f), 1);|}
\end { figure}
\begin { figure} [h]
\centering
\includegraphics [width=0.5\textwidth] { diskrand}
\cprotect \caption { \verb |vec4(diskRand(1.0f), 0, 1);|}
\end { figure}
\begin { figure} [h]
\centering
\includegraphics [width=0.5\textwidth] { ballrand}
\cprotect \caption { \verb |vec4(ballRand(1.0f), 1);|}
\end { figure}
\begin { figure} [h]
\centering
\includegraphics [width=0.5\textwidth] { gaussrand}
\cprotect \caption { \verb |vec4(gaussRand(vec3(0), vec3(1)), 1);|}
\end { figure}
\subsection { \texttt { GLM\_ GTC\_ reciprocal} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/reciprocal}
2015-12-03 18:44:15 +00:00
Reciprocal trigonometric functions (e.g. secant, cosecant, tangent).
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ round} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/round}
2015-12-03 18:44:15 +00:00
Various rounding operations and common special cases thereof.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ type\_ precision} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/type\_ precision}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Vector and matrix types with defined precisions, e.g. \verb |i8vec4|, which is a 4D vector of signed 8-bit integers.
This extension adds defines to set the default precision of each class of types added, in a manner identical to that described in section \ref { Default Precision} .
2015-11-23 19:09:35 +00:00
Available defines for signed 8-bit integer types (\verb |glm::i8vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ INT8|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ INT8|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ INT8|: High precision (default)
\end { itemize}
Available defines for unsigned 8-bit integer types (\verb |glm::u8vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ UINT8|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ UINT8|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ UINT8|: High precision (default)
\end { itemize}
Available defines for signed 16-bit integer types (\verb |glm::i16vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ INT16|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ INT16|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ INT16|: High precision (default)
\end { itemize}
Available defines for unsigned 16-bit integer types (\verb |glm::u16vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ UINT16|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ UINT16|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ UINT16|: High precision (default)
\end { itemize}
Available defines for signed 32-bit integer types (\verb |glm::i32vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ INT32|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ INT32|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ INT32|: High precision (default)
\end { itemize}
Available defines for unsigned 32-bit integer types (\verb |glm::u32vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ UINT32|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ UINT32|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ UINT32|: High precision (default)
\end { itemize}
Available defines for signed 64-bit integer types (\verb |glm::i64vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ INT64|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ INT64|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ INT64|: High precision (default)
\end { itemize}
Available defines for unsigned 64-bit integer types (\verb |glm::u64vec|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ UINT64|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ UINT64|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ UINT64|: High precision (default)
\end { itemize}
Available defines for 32-bit floating-point types (\verb |glm::f32vec|*, \verb |glm::f32mat|*, \verb |glm::f32quat|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ FLOAT32|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ FLOAT32|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ FLOAT32|: High precision (default)
\end { itemize}
Available defines for 64-bit floating-point types (\verb |glm::f64vec|*, \verb |glm::f64mat|*, \verb |glm::f64quat|*):
\begin { itemize}
\item \verb |GLM_ PRECISION_ LOWP_ FLOAT64|: Low precision
\item \verb |GLM_ PRECISION_ MEDIUMP_ FLOAT64|: Medium precision
\item \verb |GLM_ PRECISION_ HIGHP_ FLOAT64|: High precision (default)
\end { itemize}
2015-11-27 22:20:30 +00:00
\subsection { \texttt { GLM\_ GTC\_ type\_ ptr} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/type\_ ptr}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Facilitate interactions between pointers to raw values (e.g. \verb |float*|) and GLM types (e.g. \verb |mat4|).
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
This extension defines an overloaded function, \verb |glm::value_ ptr|, which returns a pointer to the memory layout of any GLM vector or matrix (\verb |vec3|, \verb |mat4|, etc.). Matrix types store their values in \textbf { column-major order} . This is useful for uploading data to matrices or for copying data to buffer objects.
2015-11-23 19:09:35 +00:00
\begin { cppcode}
2015-12-03 18:44:15 +00:00
// GLM_ GTC_ type_ ptr provides a safe solution:
2015-11-23 19:09:35 +00:00
#include <glm/glm.hpp>
#include <glm/gtc/type_ ptr.hpp>
void foo()
{
glm::vec4 v(0.0f);
glm::mat4 m(1.0f);
glVertex3fv(glm::value_ ptr(v))
glLoadMatrixfv(glm::value_ ptr(m));
}
\end { cppcode}
\begin { cppcode}
2015-12-03 18:44:15 +00:00
// Another solution, this one inspired by the STL:
2015-11-23 19:09:35 +00:00
#include <glm/glm.hpp>
void foo()
{
glm::vec4 v(0.0f);
glm::mat4 m(1.0f);
glVertex3fv(& v[0]);
glLoadMatrixfv(& m[0][0]);
}
\end { cppcode}
2015-12-03 18:42:23 +00:00
Note: It's possible to implement \glfunction { 2} { glVertex} and similar functions by defining an implicit cast from GLM types to pointer types. However, you risk triggering undefined behavior by doing so.
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ ulp} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/ulp}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Measure a function's accuracy given a reference implementation of it. This extension works on floating-point data and provides results in \href { http://ljk.imag.fr/membres/Carine.Lucas/TPScilab/JMMuller/ulp-toms.pdf} { ULP} .
2015-11-23 19:09:35 +00:00
\subsection { \texttt { GLM\_ GTC\_ vec1} }
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/vec1}
2015-11-23 19:09:35 +00:00
Add *\verb |vec1| types.
\newpage { }
2015-11-27 22:37:23 +00:00
\section { Substituting Deprecated OpenGL Functions}
2015-11-23 19:09:35 +00:00
2015-11-27 22:37:23 +00:00
\subsection { OpenGL Substitutes}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:15 +00:00
Most fixed-function APIs were deprecated in OpenGL 3.1, and then removed entirely in OpenGL 3.2. GLM provides substitutes for some of this lost functionality.
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glRotate} }
2015-11-23 19:09:35 +00:00
\begin { cppcode}
glm::mat4 glm::rotate(
glm::mat4 const & m,
float angle,
glm::vec3 const & axis
);
glm::dmat4 glm::rotate(
glm::dmat4 const & m,
double angle,
glm::dvec3 const & axis
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glScale} }
2015-11-23 19:09:35 +00:00
\begin { cppcode}
glm::mat4 glm::scale(
glm::mat4 const & m,
glm::vec3 const & factors
);
glm::dmat4 glm::scale(
glm::dmat4 const & m,
glm::dvec3 const & factors
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-27 22:38:19 +00:00
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glTranslate} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::mat4 glm::translate(
2015-11-27 22:37:23 +00:00
glm::mat4 const & m,
glm::vec3 const & translation
);
2015-11-23 19:09:35 +00:00
glm::dmat4 glm::translate(
2015-11-27 22:37:23 +00:00
glm::dmat4 const & m,
glm::dvec3 const & translation
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glLoadIdentity} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::mat4(1.0) or glm::mat4();
glm::dmat4(1.0) or glm::dmat4();
2015-11-27 22:37:23 +00:00
\end { cppcode}
\textbf { Extension:} None, part of GLM core
\textbf { Header:} \glmheader { glm}
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glMultMatrix} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::mat4() * glm::mat4();
glm::dmat4() * glm::dmat4();
2015-11-27 22:37:23 +00:00
\end { cppcode}
\textbf { Extension:} None, part of GLM core
\textbf { Header:} \glmheader { glm}
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glLoadTransposeMatrix} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::transpose(glm::mat4());
glm::transpose(glm::dmat4());
2015-11-27 22:37:23 +00:00
\end { cppcode}
\textbf { Extension:} None, part of GLM core
\textbf { Header:} \glmheader { glm}
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glMultTransposeMatrix} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::mat4() * glm::transpose(glm::mat4());
glm::dmat4() * glm::transpose(glm::dmat4());
2015-11-27 22:37:23 +00:00
\end { cppcode}
\textbf { Extension:} None, part of GLM core
\textbf { Header:} \glmheader { glm}
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glFrustum} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::mat4 glm::frustum(
2015-11-27 22:37:23 +00:00
float left, float right,
float bottom, float top,
float zNear, float zFar
);
2015-11-23 19:09:35 +00:00
glm::dmat4 glm::frustum(
2015-11-27 22:37:23 +00:00
double left, double right,
double bottom, double top,
double zNear, double zFar
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:23 +00:00
\subsubsection { \glfunction { 2} { glOrtho} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
2015-11-23 19:09:35 +00:00
glm::mat4 glm::ortho(
2015-11-27 22:37:23 +00:00
float left, float right,
float bottom, float top,
float zNear, float zFar
);
2015-11-23 19:09:35 +00:00
glm::dmat4 glm::ortho(
2015-11-27 22:37:23 +00:00
double left, double right,
double bottom, double top,
double zNear, double zFar
);
\end { cppcode}
2015-11-23 19:09:35 +00:00
2015-11-27 22:37:23 +00:00
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
2015-11-23 19:09:35 +00:00
2015-11-27 22:37:23 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-23 19:09:35 +00:00
2015-11-27 22:37:23 +00:00
\subsection { GLU Substitutes}
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:23 +00:00
\subsubsection { \glufunction { gluLookAt} }
2015-11-23 19:09:35 +00:00
\begin { cppcode}
glm::mat4 glm::lookAt(
glm::vec3 const & eye,
glm::vec3 const & center,
glm::vec3 const & up
);
glm::dmat4 glm::lookAt(
glm::dvec3 const & eye,
glm::dvec3 const & center,
glm::dvec3 const & up
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
2015-11-27 21:43:09 +00:00
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-23 19:09:35 +00:00
2015-12-03 18:42:23 +00:00
\subsubsection { \glufunction { gluOrtho2D} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
glm::mat4 glm::ortho(
float left, float right, float bottom, float top
);
glm::dmat4 glm::ortho(
double left, double right, double bottom, double top
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-12-03 18:42:23 +00:00
\subsubsection { \glufunction { gluPerspective} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
glm::mat4 perspective(
float fovy, float aspect, float zNear, float zFar
);
glm::dmat4 perspective(
double fovy, double aspect, double zNear, double zFar
);
\end { cppcode}
2015-12-03 18:44:15 +00:00
Note that in GLM, \verb |fovy| is expressed in \emph { radians} , not degrees.
2015-11-27 22:37:23 +00:00
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-12-03 18:42:23 +00:00
\subsubsection { \glufunction { gluPickMatrix} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
glm::mat4 pickMatrix(
glm::vec2 const & center,
glm::vec2 const & delta,
glm::ivec4 const & viewport
);
glm::dmat4 pickMatrix(
glm::dvec2 const & center,
glm::dvec2 const & delta,
glm::ivec4 const & viewport
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-12-03 18:42:23 +00:00
\subsubsection { \glufunction { gluProject} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
glm::vec3 project(
glm::vec3 const & obj,
glm::mat4 const & model,
glm::mat4 const & proj,
glm::vec4 const & viewport
);
glm::dvec3 project(
glm::dvec3 const & obj,
glm::dmat4 const & model,
glm::dmat4 const & proj,
glm::vec4 const & viewport
);
\end { cppcode}
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-12-03 18:42:23 +00:00
\subsubsection { \glufunction { gluUnProject} }
2015-11-27 22:37:23 +00:00
\begin { cppcode}
glm::vec3 unProject(
glm::vec3 const & win,
glm::mat4 const & model,
glm::mat4 const & proj,
glm::vec4 const & viewport
);
glm::dvec3 unProject(
glm::dvec3 const & win,
glm::dmat4 const & model,
glm::dmat4 const & proj,
glm::vec4 const & viewport
);
\end { cppcode}
2015-11-23 19:09:35 +00:00
2015-11-27 22:37:23 +00:00
\textbf { Extension:} \verb |GLM_ GTC_ matrix_ transform|
\textbf { Header:} \glmheader { gtc/matrix\_ transform}
2015-11-23 19:09:35 +00:00
\section { Known Issues}
2015-12-03 18:44:34 +00:00
This section reports GLSL features that GLM can't accurately emulate due to language restrictions.
2015-11-23 19:09:35 +00:00
2015-11-27 22:21:29 +00:00
\subsection { The \texttt { not} Function}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:34 +00:00
The GLSL function \verb |not| is a keyword in C++. To prevent name collisions and ensure a consistent API, the name \verb |not_ | (note the underscore) is used instead.
2015-11-23 19:09:35 +00:00
2015-11-27 22:21:29 +00:00
\subsection { Precision Qualifiers}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:34 +00:00
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|.
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:34 +00:00
As in GLSL, GLM precision qualifiers are used to exchange precision for performance. By default, all types use high precision.
2015-11-23 19:09:35 +00:00
\begin { glslcode}
// Using precision qualifier in GLSL:
ivec3 foo(in vec4 v)
{
highp vec4 a = v;
mediump vec4 b = a;
lowp ivec3 c = ivec3(b);
returnc;
}
\end { glslcode}
\begin { cppcode}
// Using precision qualifier in GLM:
#include <glm/glm.hpp>
ivec3 foo(const vec4 & v)
{
highp_ vec4 a = v;
medium_ vec4 b = a;
lowp_ ivec3 c = glm::ivec3(b);
returnc;
}
\end { cppcode}
2015-12-03 18:44:34 +00:00
The syntax for default precision specifications in GLM differs from that in GLSL; for more information, see section \ref { Default Precision} .
2015-11-23 19:09:35 +00:00
\newpage { }
\section { FAQ}
\subsection { Why does GLM follow the GLSL specification?}
2015-12-03 18:45:13 +00:00
Everyone and their dog has their own idea of what should constitute a math library. The designers of GLSL (the OpenGL ARB) make a living on deciding what its own should offer; why not learn from the best and stick to a proven convention?
2015-11-23 19:09:35 +00:00
\subsection { Does GLM actually run GLSL?}
2015-11-27 21:44:10 +00:00
No. GLM implements a subset of GLSL's functionality.
2015-11-23 19:09:35 +00:00
\subsection { Can GLM be compiled to GLSL (or vice versa)?}
2015-11-27 21:44:10 +00:00
No. That is not one of GLM's goals.
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\subsection { What's the difference between GTX, GTC, and Core?}
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
GTX extensions are considered \emph { experimental} , and may thus introduce breaking changes without warning (though in practice this doesn't happen often). GTC extensions are considered \emph { stable} , and are therefore unlikely to introduce radical changes. Core libraries are based entirely on functionality provided by GLSL, and can safely be relied upon. The GTX and GTC extension system provides a way to experiment with new GLM functionality, in the hopes of eventually promoting it to a GTC extension. OpenGL itself is developed in much the same way.
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
%\subsection{Where can I ask more questions about GLM??}
%
%A good place is the \href{http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=postlist&Board=10&page=1}{OpenGL Toolkits forum} on \href{http://www.opengl.org/}{OpenGL.org}.
%
% TODO: Find the real link
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\subsection { Where's the documentation?}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:50 +00:00
The Doxygen-generated documentation includes a complete list of all extensions, and can be found \href { http://glm.g-truc.net/html/index.html} { here} .
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\subsection { Should I use \texttt { using namespace glm;} ?}
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\textbf { Absolutely not!} GLM uses many common names, such as \verb |any|, \verb |scale|, and \verb |length|. Haphazardly writing \verb |using namespace glm;| will almost certainly result in name collisions. Instead, either prefix GLM calls with \verb |glm::|, or pull individual types or functions into your namespace with \verb |using glm::|*, where * is some desired name.
2015-11-23 19:09:35 +00:00
\subsection { Is GLM fast?}
2015-11-27 21:44:10 +00:00
GLM is designed for convenience over performance. \emph { That being said} , the most frequently-used operations are optimized to the fullest reasonable extent. Approximations and SIMD-flavored structures are provided as well, in case they're needed.
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\subsection { Visual C++ gives me lots of warnings on on warning level \texttt { /W4} .}
2015-11-23 19:09:35 +00:00
2015-12-03 18:44:50 +00:00
You should not have any warnings, even in \verb |/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 (\verb |/Za|) which generates warnings when used. If these extensions are enabled, then GLM will take advantage of them and the compiler will generate warnings.
2015-11-23 19:09:35 +00:00
\subsection { Why are some GLM functions vulnerable to division by zero?}
2015-12-03 18:44:50 +00:00
Such behavior follows the precedent set by C and C++'s standard library, in that it's treated as a domain error. For example, it's a domain error to pass a null vector (all zeroes) to \verb |glm::normalize|, or to pass a negative number into \verb |std::sqrt|.
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\subsection { What unit does GLM use for angles?}
2015-11-23 19:09:35 +00:00
2015-11-27 21:44:10 +00:00
\textbf { All angles in GLM are expressed in radians unless otherwise noted.} GLSL does the same thing. GLU uses degrees, however. This used to cause a lot of confusion. For more information, see \href { http://www.g-truc.net/post-0693.html#menu} { here} .
2015-11-23 19:09:35 +00:00
\newpage { }
\section { Code Samples}
2015-12-03 18:45:13 +00:00
\subsection { Triangle Normal}
2015-11-23 19:09:35 +00:00
\begin { cppcode}
#include <glm/glm.hpp> // vec3 normalize cross
glm::vec3 computeNormal
(
glm::vec3 const & a,
glm::vec3 const & b,
glm::vec3 const & c
)
{
return glm::normalize(glm::cross(c - a, b - a));
}
\end { cppcode}
\begin { cppcode}
2015-11-27 22:19:54 +00:00
// A faster (but less accurate) alternative:
2015-11-23 19:09:35 +00:00
#include <glm/glm.hpp> // vec3 cross
#include <glm/gtx/fast_ square_ root.hpp> // fastNormalize
glm::vec3 computeNormal
(
glm::vec3 const & a,
glm::vec3 const & b,
glm::vec3 const & c
)
{
return glm::fastNormalize(glm::cross(c - a, b - a));
}
\end { cppcode}
2015-11-27 22:38:19 +00:00
2015-11-23 19:09:35 +00:00
\subsection { Matrix Transformations}
2015-11-27 22:19:54 +00:00
\begin { cppcode}
#include <glm/glm.hpp> // vec3, vec4, ivec4, mat4
#include <glm/gtc/matrix_ transform.hpp> // translate, scale, etc.
#include <glm/gtc/type_ ptr.hpp> // value_ ptr
using glm::mat4;
using glm::vec3;
2015-11-23 19:09:35 +00:00
void setUniformMVP
(
2015-11-27 22:19:54 +00:00
GLuint Location,
vec3 const & Translate,
vec3 const & Rotate
2015-11-23 19:09:35 +00:00
)
{
2015-11-27 22:19:54 +00:00
mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);
mat4 ViewTranslate = glm::translate(
mat4(1.0f),
Translate
);
mat4 ViewRotateX = glm::rotate(
ViewTranslate,
Rotate.y,
vec3(-1.0f, 0.0f, 0.0f)
);
mat4 View = glm::rotate(
ViewRotateX,
Rotate.x,
vec3(0.0f, 1.0f, 0.0f)
);
mat4 Model = glm::scale(
mat4(1.0f),
vec3(0.5f)
);
mat4 MVP = Projection * View * Model;
glUniformMatrix4fv(Location, 1, GL_ FALSE, glm::value_ ptr(MVP));
2015-11-23 19:09:35 +00:00
}
2015-11-27 22:19:54 +00:00
\end { cppcode}
\subsection { Vector Types}
\begin { cppcode}
2015-11-23 19:09:35 +00:00
#include <glm/glm.hpp> //vec2
#include <glm/gtc/type_ precision.hpp> //hvec2, i8vec2, i32vec2
2015-11-27 22:19:54 +00:00
using glm::vec2;
using glm::hvec2;
using glm::i8vec2;
using glm::i32vec2;
2015-11-23 19:09:35 +00:00
std::size_ t const VertexCount = 4;
// Float quad geometry
2015-11-27 22:19:54 +00:00
std::size_ t const PositionSizeF32 = VertexCount * sizeof(vec2);
vec2 const PositionDataF32[VertexCount] =
2015-11-23 19:09:35 +00:00
{
2015-11-27 22:19:54 +00:00
vec2(-1.0f,-1.0f),
vec2( 1.0f,-1.0f),
vec2( 1.0f, 1.0f),
vec2(-1.0f, 1.0f)
2015-11-23 19:09:35 +00:00
} ;
2015-11-27 22:19:54 +00:00
2015-11-23 19:09:35 +00:00
// Half-float quad geometry
2015-11-27 22:19:54 +00:00
std::size_ t const PositionSizeF16 = VertexCount * sizeof(hvec2);
hvec2 const PositionDataF16[VertexCount] =
2015-11-23 19:09:35 +00:00
{
2015-11-27 22:19:54 +00:00
hvec2(-1.0f, -1.0f),
hvec2( 1.0f, -1.0f),
hvec2( 1.0f, 1.0f),
hvec2(-1.0f, 1.0f)
2015-11-23 19:09:35 +00:00
} ;
2015-11-27 22:19:54 +00:00
2015-11-23 19:09:35 +00:00
// 8 bits signed integer quad geometry
2015-11-27 22:19:54 +00:00
std::size_ t const PositionSizeI8 = VertexCount * sizeof(i8vec2);
i8vec2 const PositionDataI8[VertexCount] =
2015-11-23 19:09:35 +00:00
{
2015-11-27 22:19:54 +00:00
i8vec2(-1,-1),
i8vec2( 1,-1),
i8vec2( 1, 1),
i8vec2(-1, 1)
2015-11-23 19:09:35 +00:00
} ;
2015-11-27 22:19:54 +00:00
2015-11-23 19:09:35 +00:00
// 32 bits signed integer quad geometry
2015-11-27 22:19:54 +00:00
std::size_ t const PositionSizeI32 = VertexCount * sizeof(i32vec2);
i32vec2 const PositionDataI32[VertexCount] =
2015-11-23 19:09:35 +00:00
{
2015-11-27 22:19:54 +00:00
i32vec2(-1,-1),
i32vec2( 1,-1),
i32vec2( 1, 1),
i32vec2(-1, 1)
2015-11-23 19:09:35 +00:00
} ;
2015-11-27 22:19:54 +00:00
\end { cppcode}
\subsection { Lighting}
\begin { cppcode}
#include <glm/glm.hpp> // vec3, normalize, reflect, dot, pow
2015-11-23 19:09:35 +00:00
#include <glm/gtx/random.hpp> // vecRand3
2015-11-27 22:19:54 +00:00
using glm::vec3;
using glm::dot;
using glm::normalize;
2015-11-23 19:09:35 +00:00
// vecRand3, generate a random and equiprobable normalized vec3
2015-11-27 22:19:54 +00:00
vec3 lighting
2015-11-23 19:09:35 +00:00
(
2015-11-27 22:19:54 +00:00
intersection const & Intersection,
material const & Material,
light const & Light,
vec3 const & View
2015-11-23 19:09:35 +00:00
)
{
2015-11-27 22:19:54 +00:00
vec3 Color = vec3(0.0f);
vec3 LightVector = normalize(
Light.position() - Intersection.globalPosition() +
glm::vecRand3(0.0f, Light.inaccuracy()
);
if(!shadow(
Intersection.globalPosition(), Light.position(), LightVector)
)
{
float Diffuse = dot(Intersection.normal(), LightVector);
if(Diffuse <= 0.0f)
return Color;
if(Material.isDiffuse())
Color += Light.color() * Material.diffuse() * Diffuse;
if(Material.isSpecular())
{
vec3 Reflect = glm::reflect(-LightVector, Intersection.normal());
float Dot = dot(Reflect, View);
float Base = Dot > 0.0f ? Dot : 0.0f;
float Specular = glm::pow(Base, Material.exponent());
Color += Material.specular() * Specular;
}
}
return Color;
2015-11-23 19:09:35 +00:00
}
2015-11-27 22:19:54 +00:00
\end { cppcode}
2015-11-23 19:09:35 +00:00
2015-11-27 22:19:54 +00:00
\newpage { }
2015-11-23 19:09:35 +00:00
2015-11-27 22:24:49 +00:00
\section { References}
2015-11-27 22:25:21 +00:00
\subsection { Official GLM Resources}
\begin { itemize}
\item \href { http://glm.g-truc.net} { Official website}
\item \href { https://github.com/g-truc/glm/releases/tag/0.9.7.1} { Latest stable release}
\item \href { https://github.com/g-truc/glm/archive/master.zip} { HEAD snapshot}
\item \href { https://github.com/g-truc/glm/issues} { Issue tracker}
\item \href { http://www.g-truc.net} { G-Truc Creation's Website}
\end { itemize}
2015-11-27 22:25:44 +00:00
\subsection { OpenGL Specifications}
\begin { itemize}
\item \href { http://www.opengl.org/registry/doc/glspec43.core.20120806.withchanges.pdf} { OpenGL 4.3 core specification}
\item \href { http://www.opengl.org/registry/doc/GLSLangSpec.4.30.7.diff.pdf} { GLSL 4.30 specification}
\item \href { http://www.opengl.org/documentation/specs/glu/glu1_ 3.pdf} { GLU 1.3 specification}
\end { itemize}
2015-11-27 22:27:26 +00:00
\subsection { Projects Using GLM}
\subsubsection { \href { http://outerra.com/} { Outerra} }
2015-12-03 18:45:13 +00:00
A 3D planetary engine for seamless planet rendering from space down to the surface. Can use arbitrary resolution of elevation data, refining it to centimeter resolution using fractal algorithms.
2015-11-23 19:09:35 +00:00
2015-11-27 22:27:26 +00:00
\begin { center}
\includegraphics [width=0.4\textwidth] { outerra1}
\includegraphics [width=0.4\textwidth] { outerra2}
\includegraphics [width=0.4\textwidth] { outerra3}
\includegraphics [width=0.4\textwidth] { outerra4}
\end { center}
\subsubsection { \href { https://github.com/mmmovania/opencloth} { opencloth} }
A collection of cloth simulation demos, visualized with OpenGL.
\begin { center}
\includegraphics [width=0.35\textwidth] { opencloth1}
\includegraphics [width=0.35\textwidth] { opencloth2}
\includegraphics [width=0.35\textwidth] { opencloth3}
\includegraphics [width=0.35\textwidth] { opencloth4}
\end { center}
\subsubsection { \href { http://www.packtpub.com/opengl-4-0-shading-language-cookbook/book?tag=rk/opengl4-abr1/0811} { OpenGL 4.0 Shading Language Cookbook} }
\begin { wrapfigure} { r} { 0.25\textwidth }
\includegraphics [width=0.25\textwidth, right] { glsl4book}
\end { wrapfigure}
2015-11-23 19:09:35 +00:00
2015-12-03 18:45:13 +00:00
A set of recipes that demonstrates a wide variety of techniques for producing high-quality, real-time 3D graphics with GLSL 4.0, such as:
2015-11-27 22:27:26 +00:00
2015-12-03 18:45:13 +00:00
\begin { itemize}
\item Using GLSL 4.0 to implement lighting and shading techniques.
\item Using the new features of GLSL 4.0 including tessellation and geometry shaders.
\item Using textures in GLSL as part of a wide variety of techniques from basic texture mapping to deferred shading.
\end { itemize}
2015-11-27 22:27:26 +00:00
2015-12-03 18:45:13 +00:00
Simple, easy-to-follow examples with GLSL source code are provided, as well as a basic description of the theory behind each technique.
2015-11-23 19:09:35 +00:00
2015-11-27 22:27:26 +00:00
\subsubsection { \href { http://www.leosfortune.com/} { Leo's Forture} }
\begin { wrapfigure} { r} { 0.4\textwidth }
\includegraphics [width=0.4\textwidth, right] { leosfortune}
\includegraphics [width=0.4\textwidth, right] { leosfortune2}
\end { wrapfigure}
2015-11-23 19:09:35 +00:00
2015-12-03 18:45:13 +00:00
Leo's Fortune is a platform adventure game in which you hunt down the cunning and mysterious thief that stole your gold. Available on PS4, Xbox One, PC, Mac, iOS and Android.
2015-11-27 22:27:26 +00:00
2015-12-03 18:45:13 +00:00
Beautiful hand-crafted levels bring Leo's story to life in this epic adventure.
2015-11-27 22:27:26 +00:00
\say { 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.}
\say { Despite this pickle of a trap, I am left with no choice but to follow the trail.}
\say { Whatever lies ahead, I must recover my fortune.} ---Leopold
2015-12-03 18:42:23 +00:00
Are you using GLM in a project? \glmemail { Tell us!}
2015-11-27 22:27:26 +00:00
2015-11-27 22:27:46 +00:00
\subsection { OpenGL Tutorials using GLM}
\begin { itemize}
\item \href { http://www.g-truc.net/project-0026.html#menu} { The OpenGL Samples Pack} : Examples that demonstrate OpenGL's many features
\item \href { http://www.arcsynthesis.org/gltut/} { Learning Modern 3D Graphics Programming} : A great OpenGL tutorial by Jason L. McKesson
\item \href { http://blog.nobel-joergensen.com/2011/04/02/glm-brilliant-math-library-for-opengl/} { Morten Nobel-Jørgensen's review} and \href { https://github.com/mortennobel/RenderE} { OpenGL renderer}
\item \href { http://www.swiftless.com/opengltuts.html} { Swiftless' OpenGL tutorial} by Donald Urquhart
\item \href { http://rastergrid.com/blog/} { Rastergrid} : Technical articles (with companion programs) by Daniel Rákos
\item \href { http://www.opengl-tutorial.org} { OpenGL Tutorial} : OpenGL tutorials
\item \href { http://en.wikibooks.org/wiki/OpenGL_ Programming} { OpenGL Programming on Wikibooks} : For beginners just discovering OpenGL
\item \href { http://3dgep.com/} { 3D Game Engine Programming} : 3D game engine programming techniques
\item \href { http://www.gametutorials.com/opengl-4-matrices-and-glm/} { Game Tutorials} : Graphics and game programming tutorials
\item \href { https://open.gl/} { open.gl} : An OpenGL tutorial
\item \href { http://www.c-jump.com/bcc/common/Talk3/Math/GLM/GLM.html} { c-jump} : A GLM tutorial
\item \href { http://learnopengl.com/} { Learn OpenGL} : An OpenGL tutorial
\end { itemize}
2015-12-03 18:42:23 +00:00
Are you using GLM in a tutorial? \glmemail { Tell us!}
2015-11-27 22:27:46 +00:00
2015-11-23 19:09:35 +00:00
2015-11-27 22:28:05 +00:00
\subsection { Alternatives to GLM}
\begin { itemize}
\item \href { http://cmldev.net/} { CML} : The CML (Configurable Math Library) is a free C++ math library for games and graphics.
2015-12-03 18:45:13 +00:00
\item \href { http://eigen.tuxfamily.org/} { Eigen} : A more heavy weight math library for general linear algebra.
2015-11-27 22:28:05 +00:00
\end { itemize}
2015-12-03 18:42:23 +00:00
Are you using or developing an alternative to GLM? \glmemail { Tell us!}
2015-11-27 22:28:05 +00:00
2015-11-27 22:22:58 +00:00
\subsection { Acknowledgements}
GLM is developed and maintained by \href { http://www.g-truc.net} { Christophe Riccio} , but relies on the support of its many contributors to stay great.
2015-11-23 19:09:35 +00:00
Special thanks to:
2015-11-27 22:22:58 +00:00
\begin { itemize}
\item Ashima Arts and Stefan Gustavson for their work on \href { https://github.com/ashima/webgl-noise} { webgl-noise} , which which is the base of \verb |GLM_ GTC_ noise|.
\item \href { http://athile.net/library/wiki/index.php?title=Athile_ Technologies} { Arthur Winters} for contributing to the swizzle operator implementation.
2015-12-03 18:45:13 +00:00
\item Joshua Smith and Christoph Schied for their contributions to the swizzle expression implementation.
2015-11-27 22:22:58 +00:00
\item Guillaume Chevallereau for providing and maintaining the \href { http://my.cdash.org/index.php?project=GLM} { nightly build system} .
\item Ghenadii Ursachi for \verb |GLM_ GTX_ matrix_ interpolation|.
\item Mathieu Roumillac for providing some implementation ideas.
\item \href { http://www.zeuscmd.com/} { Grant James} for non-square matrix multiplication (e.g. \verb |mat3 * 3x2|)
\item GLM's users! Without you, there is no GLM!
\end { itemize}
\subsection { Quotes from the web}
\say { I am also going to make use of boost for its time framework and the matrix library GLM, a GL Shader-like Math library for C++. A little advertise for the latter which has a nice design and is useful since matrices have been removed from the latest OpenGL versions.}
\begin { flushright}
---\href { http://www.codexperiments.com/android/2010/10/android-sdk-ndk-part-4-the-silver-bullet-of-android/} { Code Xperiments}
\end { flushright}
\say { OpenGL Mathematics Library (GLM): Used for vector classes, quaternion classes, matrix classes and math operations that are suited for OpenGL applications.}
\begin { flushright}
---\href { http://3dgep.com/?p=1116} { Jeremiah van Oosten}
\end { flushright}
\say { Today I ported my code base from my own small linear algebra library to GLM, a GLSL-style vector library for C++. The transition went smoothly.}
\begin { flushright}
---\href { http://devel.leonard-ritter.com/2011/08/planning-sparse-voxel-octrees.html} { Leonard Ritter}
\end { flushright}
\say { A more clever approach is to use a math library like GLM instead. I wish someone had showed me this library a few years ago.}
\begin { flushright}
---\href { http://blog.nobel-joergensen.com/2011/04/02/glm-brilliant-math-library-for-opengl/} { Morten Nobel-Jørgensen}
\end { flushright}
2015-11-23 19:09:35 +00:00
\end { document}