Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL - GLM and GLSL, how are they different?

I am starting to learn about OpenGL and GLM and GLSL and I am getting a little confused. I will say in here what I have understood so far and my questions, so please feel free to correct me anytime.

So far I see that GLM extends the GLSL documentation providing more math functions, but since GLM is C++ based it will run on the CPU, on the other hand, GLSL runs directly in the GPU so I guess matrix math is a lot faster in GLSL since it can use the GPU's power to do all the math in parallel. So why to use GLM?

like image 233
Michel Feinstein Avatar asked Nov 13 '13 05:11

Michel Feinstein


2 Answers

They're completely different things:

  • GLSL is the language used to write shader programs that run on the GPU. It's a variant of C with some special OpenGL-specific extensions. But as far as your application is concerned, a GLSL shader is just an opaque data file to be passed to the OpenGL library; it's completely independent of the host program.
  • GLM is a C++ library for working with vector data on the CPU. For convenience, it follows similar naming conventions to GLSL, but it's completely independent of OpenGL.

GLM isn't meant as a substitute or alternative to GLSL. It's meant to help with calculations that wouldn't make sense to do on the GPU — things like building a projection matrix to be used by your vertex shaders, or computing distances between points in 3D space.

like image 150
Wyzard Avatar answered Sep 29 '22 17:09

Wyzard


They're two completely different things:

  • GLSL (OpenGL Shading Language) is a language used by OpenGL (syntax based on C) to run programs on the GPU, called shaders, which you know the purpose of. They're not even part of your program - instead, they are two files stored in your computer which at runtime are passed to OpenGL and only then they're compiled. It provides advanced math for two reasons: there's no way to load libraries, and because this is graphics programming, which is very related to math.
  • GLM (OpenGL Mathematics) is a C++ library used to extend C++'s math capabilities with functions and types that are commonly used in graphics programming - all this will be executed on the CPU, and it's independent from OpenGL.

The reason GLM has OpenGL in its name is because it was built with graphics programming in their minds (in other words, made for OpenGL).

Short version: GLM is for your program, GLSL's math capabilities are for your shader.

like image 37
jv110 Avatar answered Sep 29 '22 18:09

jv110