LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: blindstone on March 01, 2012, 03:10:58

Title: Help with understanding use of Matrix4f
Post by: blindstone on March 01, 2012, 03:10:58
Hey everyone, looking for a bit of guidance using matrix4f in a 3d environment.

i acknowledge (I believe so anyways) what matrices are and how to add/sub/multiple them properly, however I am having a hard time understanding how to use them properly.

As in when using matrix's should I ever have to use glTranslatef anymore? or is it all based off of calculating matrix's?

(sorry if this sounds dumb perhaps im not explaining it correctly or getting the full meaning behind them.)
Title: Re: Help with understanding use of Matrix4f
Post by: spasi on March 17, 2012, 13:08:35
In modern OpenGL all functions that manipulate the fixed function matrix stacks have been deprecated. In a core GL context there's no Translatef/Rotatef/MultMatrix/PopMatrix/etc. That means that the recommended way (and only possible way in GL core) is to build the transformation matrix client-side, then doing a single call to UniformMatrix4f to update the bound shader's MVP matrix uniform.

Even if we ignore GL core, it's still the preferred way of doing it. There's less overhead in doing it client-side (less JNI calls) and the GL driver has less state to track and update. In fixed function OpenGL you'd use glLoadMatrix instead of glUniformMatrix.