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]);
}