SFML community forums

Help => General => Topic started by: scottyaim on October 07, 2016, 10:33:24 pm

Title: glm::mat4 in setUniform?
Post by: scottyaim on October 07, 2016, 10:33:24 pm
Hi, I am trying to load a glm::mat4 into a shader but there are no overloads for glm::mat4 in shader.setUniform().

Is there any why to upload a glm::mat4 into a uniform with shader.setUniform()?
Title: Re: glm::mat4 in setUniform?
Post by: dabbertorres on October 08, 2016, 06:45:07 am
Because SFML isn't GLM?

You'll need to pass it as a sf::Glsl::Mat4.
Title: Re: glm::mat4 in setUniform?
Post by: scottyaim on October 09, 2016, 01:16:49 pm
Because SFML isn't GLM?

You'll need to pass it as a sf::Glsl::Mat4.

Okay i see. What is an easy why to pass a glm::mat4 for into a Glsl::mat4?
Title: Re: glm::mat4 in setUniform?
Post by: Laurent on October 09, 2016, 01:54:26 pm
It's not that hard, just look at the documentation.

Quote
The matrix can be constructed from an array with 4x4
elements, aligned in column-major order. For example,
a translation by (x, y, z) looks as follows:

float array[16] =
{
    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    x, y, z, 1
};
sf::Glsl::Mat4 matrix(array);

And then in glm::mat4 you have glm::value_ptr to get a float* out of a glm::mat4.
Title: Re: glm::mat4 in setUniform?
Post by: scottyaim on October 09, 2016, 02:50:57 pm
It's not that hard, just look at the documentation.

Quote
The matrix can be constructed from an array with 4x4
elements, aligned in column-major order. For example,
a translation by (x, y, z) looks as follows:

float array[16] =
{
    1, 0, 0, 0,
    0, 1, 0, 0,
    0, 0, 1, 0,
    x, y, z, 1
};
sf::Glsl::Mat4 matrix(array);

And then in glm::mat4 you have glm::value_ptr to get a float* out of a glm::mat4.

Thank you that solved it!