Weird numbers in glGetFloat( GL11.GL_MODELVIEW_MATRIX, fb)

Started by sober, July 31, 2005, 14:17:05

Previous topic - Next topic

sober

Here is the excamplecode:

I just open GL Stuff, call LoadIdentity and than glGetFloat()
normaly the Matrix should look like:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

so the System.out.println should print something like 1 right?

Well, I get a "Weird Number: 4.6006E-41"

Anyone around, who can tell me how to get Numbers I can work with?
I testet glGetInteger, glGetDouble and glGetPointer also, no better result...

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.GLU;

public class MatrixError
{
	public static void main(String[] args)
	{
		new MatrixError();
	}
	public MatrixError()
	{
		try
		{
			DisplayMode dm = org.lwjgl.util.Display.getAvailableDisplayModes(
					800,600,800,600,32,32,60,60)[0];
			Display.setDisplayMode(dm);
			Display.setFullscreen(false);
			Display.create();
			Display.setTitle("Error");
			
			GL11.glShadeModel(GL11.GL_SMOOTH);
			GL11.glClearColor(0.0f,0.0f,0.0f,0.0f);
			GL11.glClearDepth(3.0f);
			GL11.glEnable(GL11.GL_DEPTH_TEST);
			GL11.glDepthFunc(GL11.GL_LEQUAL);
			GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT,GL11.GL_NICEST);
			
	        	GL11.glViewport(0,0,800,600);
	      	 	GL11.glMatrixMode(GL11.GL_PROJECTION);
	        	GL11.glLoadIdentity();
	        	GLU.gluPerspective(45.0f,800f/600f,0.1f,100.0f);
	        	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	        	GL11.glLoadIdentity();

	        	FloatBuffer fb = ByteBuffer.allocateDirect( 16*4).asFloatBuffer();
	        
        		GL11.glGetFloat( GL11.GL_MODELVIEW_MATRIX, fb);
        		fb.rewind();
        		System.out.println( "Weird Number: " + (float) fb.get());
        		fb.rewind();
        		Display.update();
    			Display.destroy();
	        	System.exit(0);
		}
		catch( Exception e)
		{
			/* Don't ask ;) Quick and dirty */
		}
	}
}

Orangy Tang

You didn't order your float buffer according to the native byte order. Instead use BufferUtils.createFloatBuffer() which does exactly that.