[SOLVED] JAVA AffineTransform and OPENGL

Started by mrgibson, June 23, 2013, 05:43:46

Previous topic - Next topic

mrgibson

I do some translation and zooming in a JAVA affine transform, what is the best way to use it in OPENGL (with LWJGL) ?
(I also use shaders)


Thank you,
mrgibson


quew8

You would have to extract the matrix from the affine transform and set it to your OpenGL shader. Unfortunately, as far as I know, you cannot get the matrix from the affine transform so...

Fortunately for you, translation and scaling matrices are very simple.
Translation : 1 0 0 tx Where the translation vector is (tx, ty, tz)
                  0 1 0 ty
                  0 0 1 tz
                  0 0 0 1

Scaling : sx  0   0   0 Where sx, sy, sz are the respective x, y and z scaling coefficients.
             0   sy  0   0
             0   0    sz  0
             0   0    0    1

However a sound knowledge of transformation matrices is essential for advanced OpenGL so I would advice a bit of research. I found http://www.wildbunny.co.uk/blog/vector-maths-a-primer-for-games-programmers/ to be an excellent starter.

mrgibson

Nice link.

I think I could extract the matrix using Affinetransform.getMatrix() function.

I guess I could send it to my shader then.

quew8

Sure you could. I must have missed that function (I did look through the javadoc). One thing to be careful of - make sure you get the column major / row major order the right way round.

mrgibson

This is working nicely, I ported all my code from Graphics2D to OpenGL.
I also discovered glScissor(), really simple to use for clipping regions.

Here a small video of the result:

http://www.youtube.com/watch?v=ib_3F06mwIY&feature=youtu.be

quew8

That's great work for an OpenGL beginner. You would be shocked how many people have problems with this stuff.