LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: OverBlob on September 04, 2012, 17:24:20

Title: Can't find equivalent for GLTOOLs library PopMatrix() and PushMatrix() functions
Post by: OverBlob on September 04, 2012, 17:24:20
Hello,

As the glPushMatrix() and the glPopMatrix() functions are now deprecated in the OpenGl compatibility profile(confer OpenGL superbible 5th edition), I tried to search equivalent of:

-void GLMatrixStack::PopMatrix(void);
-void GLMatrixStack::PushMatrix(void);

of the C++ GLTOOLs library in LWJGL library, but I didn't find it in the supposed most appropriated location (ie:org.lwjgl.util.vector package).

Could you please help me know how should I do to make matrix stacks? :)
Title: Re: Can't find equivalent for GLTOOLs library PopMatrix() and PushMatrix() functions
Post by: ra4king on September 04, 2012, 21:08:05
As GLTOOLS isn't part of OpenGL, it has no business being in LWJGL. You are supposed to implement your own matrix stack. LWJGL provides a Matrix4f in its util.vector package, and it's up to you to implement push and pop :)

Here's a basic implementation:

import java.util.Stack;
import org.lwjgl.util.vector.Matrix4f;

public class MatrixStack {
private Stack<Matrix4f> stack;
private Matrix4f current;

public MatrixStack() {
current = new Matrix4f();
stack = new Stack<Matrix4f>();
}

public Matrix4f getTop() {
return current;
}

public void setTop(Matrix4f m) {
current = m;
}

public void pushMatrix() {
stack.push(current);
current = new Matrix4f(current);
}

public void popMatrix() {
current = stack.pop();
}
}
Title: Re: Can't find equivalent for GLTOOLs library PopMatrix() and PushMatrix() functions
Post by: OverBlob on September 05, 2012, 16:25:46
Okay, thanks a lot , I'll do that!  :)