I do not know why, but when I try to use GL11.glRenderMode (GL11.GL_SELECT) to manage a viewfinder on the objects of my 3D scenes it gets me this error:
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
at org.lwjgl.opengl.GL11.glRenderMode(GL11.java:2573)
at Renderer.test(Renderer.java:117)
at Renderer.start(Renderer.java:77)
at Main.main(Main.java:19)
Line 117 of file Renderer.java corresponds to the line where I call to GL11.glRenderMode (GL11.GL_SELECT)!
Here is the complete code of the function:
public void test(float xcam, float zcam, float ycam)
{
GL11.glRenderMode(GL11.GL_SELECT);
IntBuffer viewport = BufferUtils.createIntBuffer(16);
FloatBuffer modelview = BufferUtils.createFloatBuffer(16);
FloatBuffer projection = BufferUtils.createFloatBuffer(16);
FloatBuffer fDepth = BufferUtils.createFloatBuffer(1);
FloatBuffer position = BufferUtils.createFloatBuffer(3);
GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
GL11.glReadPixels( SCREEN_WIDTH/2, viewport.get(3) - (SCREEN_HEIGHT/2), 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, fDepth);
GLU.gluUnProject((float)(SCREEN_WIDTH/2), viewport.get(3) - (float)(SCREEN_HEIGHT/2), fDepth.get(), modelview, projection, viewport, position);
float distMaxPick = (float)Math.sqrt(Math.pow(xcam - position.get(0), 2)+Math.pow(ycam - position.get(1), 2)+Math.pow(zcam - position.get(2), 2));
if (distMaxPick <= 2.5*CUBESIZE)
tabCube[(int)(position.get(0)/CUBESIZE)][(int)(position.get(2)/CUBESIZE)][(int)(position.get(1)/CUBESIZE)].aimed(basicTexPack, CUBESIZE);
/*
System.out.println("World coords at z=" + fDepth.get(0) + "are (" +
(int)(position.get(0)/CUBESIZE) + ", " +
(int)(position.get(1)/CUBESIZE) + ", " +
(int)(position.get(2)/CUBESIZE)+
")");
*/
GL11.glRenderMode(GL11.GL_RENDER);
}
