Hi,
In an event on a GLCanvas from SWT, I'm trying to find where the mouse look at.
code:
private Listener Event_Mouse_Hover = new Listener(){
public void handleEvent(Event event) {
Paint_Zone.setCurrent();
try {GLContext.useContext(Paint_Zone);} catch(LWJGLException e) { e.printStackTrace(); }
IntBuffer viewport = BufferUtils.createIntBuffer(16);
FloatBuffer modelview = BufferUtils.createFloatBuffer(16);
FloatBuffer projection = BufferUtils.createFloatBuffer(16);
int winX, winY;
FloatBuffer winZ = BufferUtils.createFloatBuffer(1);
FloatBuffer pos = BufferUtils.createFloatBuffer(3);//FloatBuffer.allocate(3);
GL11.glGetFloat( GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetFloat( GL11.GL_PROJECTION_MATRIX, projection);
GL11.glGetInteger( GL11.GL_VIEWPORT, viewport);
winX = event.x;
winY = viewport.get(3) - event.y;
GL11.glReadPixels( winX, winY, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ);
GLU.gluUnProject( winX, winY, winZ.get(0), modelview, projection, viewport, pos);
console.setText("Coordinates : "
+ String.valueOf(pos.get(0))+ " "
+ String.valueOf(pos.get(1))+ " "
+ String.valueOf(pos.get(2))+ " "
+ String.valueOf(winZ.get(0)));
}
};
The problem is this function works perfectly on windows but on linux glReadPixels reports always 0.0 into winZ.