Jump to page: 1 2
Thread overview
issue porting C++/glm/openGL to D/gl3n/openGL
Jan 10, 2016
WhatMeWorry
Jan 10, 2016
Mike Parker
Jan 10, 2016
WhatMeWorry
Jan 11, 2016
Dav1d
Jan 12, 2016
Mike Parker
Jan 12, 2016
rsw0x
Jan 10, 2016
rsw0x
Jan 10, 2016
WhatMeWorry
Jan 11, 2016
Luis
Jan 11, 2016
Luis
Jan 10, 2016
Johan Engelen
Jan 10, 2016
Johan Engelen
Jan 10, 2016
WhatMeWorry
January 10, 2016
Just translating some simple C++/glm/opengl tutorial code to D/gl3n/opengl and I'm coming across more friction than I expected.  I've got a square centered at my window which is rotated by 45 degrees (counter clockwise) and then moved to the lower right quadrant.

// C++ glm opengl code
glm::mat4 transform;
transform = glm::translate(transform, glm::vec3(0.0f, -0.5f, 0.0f));
transform = glm::rotate(transform, 45.0f, vec3(0.0f, 0.0f, 1.0f));   // degrees


// D gl3n opengl code
mat4 transform = mat4.identity;
transform = transform.translation(vec3(0.5f, -0.5f, 0.0f));
transform = transform.rotate(0.78539, vec3(0.0f, 0.0f, 1.0f));       // radians

My D code performs the operations fine, but in the _opposite_ order.

I thought just swapping the order would fix things:

transform = transform.rotate(0.78539, vec3(0.0f, 0.0f, 1.0f));
transform = transform.translation(vec3(0.5f, -0.5f, 0.0f));

but now the square is moved to the lower right corner but no rotation happened?

So am I using gl3n incorrectly? Are there tricks or techniques I' missing?  Is gl3n not a direct replacement for glm?

Any advice is greatly appreciated. Thanks.


January 10, 2016
On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>

> Is gl3n not a direct replacement for glm?
>

From the very top of the gl3n github page:

"OpenGL Maths for D (not glm for D)."

So, no, it is not. You might want to start with the glm documentaion [1].

[1] http://dav1dde.github.io/gl3n/


January 10, 2016
On Sunday, 10 January 2016 at 04:37:43 UTC, Mike Parker wrote:
> On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>>
>
>> Is gl3n not a direct replacement for glm?
>>
>
> From the very top of the gl3n github page:
>
> "OpenGL Maths for D (not glm for D)."
>
> So, no, it is not. You might want to start with the glm documentaion [1].
>
> [1] http://dav1dde.github.io/gl3n/


Thanks. Bummer. I really like gl3n, but glm/opengl is used almost exclusively in all the modern opengl code (tutorials) I've seen, so this might be a deal breaker.  As the author of Derelict do you have any ideas of how much work is involved with getting glm to work with D?

Want to do a DerelictGLM :)

I bought your excellent book as a xmas present for myself so looks like I'll be reading chapter 9.

January 10, 2016
On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>
> Just translating some simple C++/glm/opengl tutorial code to D/gl3n/opengl and I'm coming across more friction than I expected.  I've got a square centered at my window which is rotated by 45 degrees (counter clockwise) and then moved to the lower right quadrant.
>
> [...]

iirc, gl3n uses row major and glm uses column major ordering
just pass GL_TRUE to the transpose argument in glUniformMatrix4fv
January 10, 2016
On Sunday, 10 January 2016 at 06:35:34 UTC, rsw0x wrote:
> On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>>
>> Just translating some simple C++/glm/opengl tutorial code to D/gl3n/opengl and I'm coming across more friction than I expected.  I've got a square centered at my window which is rotated by 45 degrees (counter clockwise) and then moved to the lower right quadrant.
>>
>> [...]
>
> iirc, gl3n uses row major and glm uses column major ordering
> just pass GL_TRUE to the transpose argument in glUniformMatrix4fv

Yup. Have that already. Maybe I'll take snapshots of the transform matrix of both programs and see how they differ (if any).  The vertex shader is identical for both.
January 10, 2016
On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>
> I thought just swapping the order would fix things:
>
> transform = transform.rotate(0.78539, vec3(0.0f, 0.0f, 1.0f));
> transform = transform.translation(vec3(0.5f, -0.5f, 0.0f));
>
> but now the square is moved to the lower right corner but no rotation happened?

(Disclaimer: I know absolutely nothing about gl3n.)

Note that you wrote "translatION", instead of "translatE". Reading the documentation, "translation" does not apply but instead it sets the matrix to a certain translation. See the difference between "rotate" and "rotation" methods. It's pretty strange that there is no "translate" method...
January 10, 2016
On Sunday, 10 January 2016 at 10:35:34 UTC, Johan Engelen wrote:
> It's pretty strange that there is no "translate" method...

Didn't see it in the online docs, but in the source there is the "translate" method that you should use.
January 10, 2016
On Sunday, 10 January 2016 at 10:38:07 UTC, Johan Engelen wrote:
> On Sunday, 10 January 2016 at 10:35:34 UTC, Johan Engelen wrote:
>> It's pretty strange that there is no "translate" method...
>
> Didn't see it in the online docs, but in the source there is the "translate" method that you should use.

That's it!  Excellent catch.  Thank you.

gll3n has translate(), rotate(), and scale() and matrix operators.


It also has translation(), rotation(), and scaling() which

/// Returns a translation matrix (3x3 and 4x4 matrices).
/// Returns an identity matrix with an applied rotate_axis around an arbitrary axis (nxn matrices, n >= 3).
/// Returns a scaling matrix (3x3 and 4x4 matrices);


January 11, 2016
On Sunday, 10 January 2016 at 06:35:34 UTC, rsw0x wrote:
> On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>>
>> Just translating some simple C++/glm/opengl tutorial code to D/gl3n/opengl and I'm coming across more friction than I expected.  I've got a square centered at my window which is rotated by 45 degrees (counter clockwise) and then moved to the lower right quadrant.
>>
>> [...]
>
> iirc, gl3n uses row major and glm uses column major ordering
> just pass GL_TRUE to the transpose argument in glUniformMatrix4fv

If you like to check an D lib for vector/matrix/quaterntion operations that uses column major ordering (ie, not need to transpose), see this : https://github.com/Zardoz89/zmath

Was just my D2 learning pet project... I never checked if it was math correct, and I don't updated in a lot of time (5 years ago), plus there isn't documentation beyond comments and a few unit-tests, so use at your risk.
But at least I know that was working correctly with Derelict2 when I wrote it.

Perhaps I should retake this...
January 11, 2016
On Monday, 11 January 2016 at 10:04:29 UTC, Luis wrote:
> On Sunday, 10 January 2016 at 06:35:34 UTC, rsw0x wrote:
>> On Sunday, 10 January 2016 at 02:51:57 UTC, WhatMeWorry wrote:
>>>
>>> Just translating some simple C++/glm/opengl tutorial code to D/gl3n/opengl and I'm coming across more friction than I expected.  I've got a square centered at my window which is rotated by 45 degrees (counter clockwise) and then moved to the lower right quadrant.
>>>
>>> [...]
>>
>> iirc, gl3n uses row major and glm uses column major ordering
>> just pass GL_TRUE to the transpose argument in glUniformMatrix4fv
>
> If you like to check an D lib for vector/matrix/quaterntion operations that uses column major ordering (ie, not need to transpose), see this : https://github.com/Zardoz89/zmath
>
> Was just my D2 learning pet project... I never checked if it was math correct, and I don't updated in a lot of time (5 years ago), plus there isn't documentation beyond comments and a few unit-tests, so use at your risk.
> But at least I know that was working correctly with Derelict2 when I wrote it.
>
> Perhaps I should retake this...

I just remember why I never retake this ... Use gl3n, row-major math operations outperforms a lot, if you are doing any matrix multiplication on CPU side ( http://eli.thegreenplace.net/2015/memory-layout-of-multi-dimensional-arrays/ )
« First   ‹ Prev
1 2