Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save donaldmunro/38841d72c65a1c32f2bf83a4a00a2c9a to your computer and use it in GitHub Desktop.
Save donaldmunro/38841d72c65a1c32f2bf83a4a00a2c9a to your computer and use it in GitHub Desktop.
Display/print a GLM mat or vec
#include <glm/gtx/string_cast.hpp>
..
..
glm::mat4 mat;
..
..
std::cout << glm::to_string(mat) << std::endl;
@lead8964878
Copy link

Thanks for the information!

@Ilmu011
Copy link

Ilmu011 commented Feb 6, 2021

Thank you for this!

@Icemole
Copy link

Icemole commented Mar 15, 2021

I had to #define GLM_ENABLE_EXPERIMENTAL before I could #include <glm/gtx/string_cast.hpp>. Useful when needed, thanks.

@OwlCodR
Copy link

OwlCodR commented Mar 15, 2021

Thanks! It helps

@Neil-Lunavat
Copy link

Thank you so much for sharing this method.

@mkvenkit
Copy link

mkvenkit commented Aug 5, 2021

Very handy, thanks!

@mattermon
Copy link

useful, thanks

@JohnENoonan
Copy link

Thank you!

@AppleTesla
Copy link

im getting this error...any idea why?
No member named 'call' in 'glm::detail::compute_to_string<std::vector<glm::mat<4, 4, float, glm::packed_highp>>>'

@tomcatmew
Copy link

really helpful! thanks google bring me here

@GrayKeee
Copy link

why i got "No member named 'to_string' in namespace 'glm'"

@HaochenWang1243
Copy link

Thanks!!

@HaochenWang1243
Copy link

why i got "No member named 'to_string' in namespace 'glm'"

bro go ahead and #include <glm/gtx/string_cast.hpp>

@D1ngkai
Copy link

D1ngkai commented Mar 21, 2023

Thanks!!

@MuhammadSulaiman001
Copy link

Use built-in << overload

#include <glm/gtx/io.hpp>

auto mat = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 100.0f);
cout << mat << endl;

Gives


[[    0.002,    0.000,    0.000,   -1.000]
 [    0.000,    0.003,    0.000,   -1.000]
 [    0.000,    0.000,   -0.020,   -1.002]
 [    0.000,    0.000,    0.000,    1.000]]

Copy link

ghost commented May 26, 2024

im getting this error...any idea why? No member named 'call' in 'glm::detail::compute_to_string<std::vector<glm::mat<4, 4, float, glm::packed_highp>>>'

It's confused between std::to_string and glm::to_string.

@rarepng
Copy link

rarepng commented Jun 3, 2024

how do u resolve this confusion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment