Modelview and Projection Matrix

I’m trying to get the modelview and projection matrices. Normally, I’d do something along the lines of


float params[] = new float[16];
gl.getFloatv(GL.MODELVIEW_MATRIX, params);
gl.getFloatv(GL.PROJECTION_MATRIX, params);

However, it wants params to be an integer. How should I do this? I want the final values to be in an array of floats.

Thanks.

-Nick

Edit: I’m using LWJGL 0.6

Wow, LWJGL 0.6 - you might want to consider upgrading to 0.8 at some point, as things like this particular nastiness have completely gone away.

The integer argument here is a pointer to a direct buffer of float data. Try something like the following:

FloatBuffer fb = ByteBuffer.allocateDirect(16 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
int fb_addr = Sys.getDirectBufferAddress(fb);
gl.getFloatv(GL.MODELVIEW_MATRIX, fb_addr);

You need upgrade to 0.8 :stuck_out_tongue:

But if you insist on using 0.6, you need to get the address of the buffer (which has to be a direct buffer) using Sys.getDirectBufferAddress():


FloatBuffer params = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer();
gl.getFloatv(GL.MODELVIEW_MATRIX, Sys.getDirectBufferAddress(params));

Cas :slight_smile:

Bah! Bloody forum lag!

Cas :slight_smile:

;D

Thanks guys.

And I’ll be using version 0.6 until I see glu.cylinder in the newer versions. ;D

Gah! How hard can it be to write a cylinder drawing routine! It’s about 20-30 lines of code at most. Go and look at the GLU sources to see what I mean…

Cas :slight_smile:

 [float[] params2=new float[16];
            FloatBuffer params = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer();//FloatBuffer.wrap(params2);
            //ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer();
            //System.out.println("Getting Modelview");
            gl.getFloatv(GL.MODELVIEW_MATRIX, Sys.getDirectBufferAddress(params));
            for(int r=0; r<16; r++)
            {
                params2[r]=params.get(r);
                System.out.println(params2[r]);

            }
            BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
            try
            {
                stdin.readLine();
            }
            catch(IOException e){ }
            params.clear();
            //params2=params.array();
            Matrix4f modelview = new Matrix4f(params2);
            modelview.transpose(modelview);
            //System.out.println("Getting Projection");
            gl.getFloatv(GL.PROJECTION_MATRIX, Sys.getDirectBufferAddress(params));
            //params2=params.array();
            for(int r=0; r<16; r++)
            {
                params2[r]=params.get(r);
                System.out.println(params2[r]);
            }
            try
            {
                stdin.readLine();
            }
            catch(IOException e){ }
            params.clear();

I’ll start on that as soon as I get this to work.

This is in drawGLScene. The first time, it works fine. params is filled, and I think it more or less works. After that, params2 is always set to zero. This occurs with our without the params.clear calls made. Anyone know why this would happen?

Thanks.

-Nick