LWJGL gluUnproject issues

I am my own worst enemy. For some odd reason LWJGL requires buffers and this is the best I can come up with.
In the end I get this error:

[quote]java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 16
[/quote]
Can someone please help me with my mess? Thanks.

	private Vector2f convertScrToWorld(float x, float y) throws Exception
	{
		float[][] modelview = new float[4][4];
		float[] model = new float[16];
		
		float[][] projection = new float[4][4];
		float[] proj = new float[16];
		
		int[] view = new int[4];
		float[] pos = new float[]{x, y, 0};
		
		FloatBuffer buffMod = ByteBuffer.allocateDirect(16*4).asFloatBuffer();
		buffMod = buffMod.get(model);
		
		FloatBuffer projMod = ByteBuffer.allocateDirect(16*4).asFloatBuffer();
		projMod = projMod.get(proj);
		
		IntBuffer viewMod = ByteBuffer.allocateDirect(4*4).asIntBuffer();
		viewMod = viewMod.get(view);
		
		GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, buffMod);
		GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projMod);
		GL11.glGetInteger(GL11.GL_VIEWPORT, viewMod);
		
		GLU.gluUnProject(
			x, view[3] - y, 0,
			modelview,
			projection,
			view,
			pos
		);
		
		System.out.println(pos[0] + " " + pos[1]);
		
		return new Vector2f(pos[0], pos[1]);
	}

rewind buffers?
do note that some buffers are requred to be bigger than they actually have to be, due to the generic error checking.

Thanks fixed.
Now I just have to get it to manipulate my coords.

It’s not doing anything now.

I don’t know why but working with buffers isn’t as conveniant as arrays even though they are effectively the same concept.

same here: I have to agree with Kiler. Working with arrays would be more convenient.


	private final FloatBuffer a_LightPosition_fb = BufferUtils.createFloatBuffer(16);

	a_LightPosition[0] = 10.0f*(float)Math.sin(a_counter*4.0f*3.14f/360.0f);
	a_LightPosition[1] = 0.0f+10.0f*(float)Math.sin(a_counter*2*3.14/360.0);
	a_LightPosition[2] = 3.0f-2.5f*(float)Math.cos(a_counter*8.0f*3.14f/360.0f);
				
	a_LightPosition_fb.put(a_LightPosition).rewind();

	GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, a_LightPosition_fb);

would simply read


	a_LightPosition[0] = 10.0f*(float)Math.sin(a_counter*4.0f*3.14f/360.0f);
	a_LightPosition[1] = 0.0f+10.0f*(float)Math.sin(a_counter*2*3.14/360.0);
	a_LightPosition[2] = 3.0f-2.5f*(float)Math.cos(a_counter*8.0f*3.14f/360.0f);
	GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, a_LightPosition);

true, problem is its slower when passing through JNI.
It’s a bit of a tricky issue, since using arrays is probably faster on the Java side and buffers are faster on the JNI side.

is GetPrimitiveArrayCritical() so slow or it’s the JNI overhead ?

Why not just use buffers exclusive to the method instead of 2D arrays?