Here’s my testcase I hope it shows the problem. I cant test it with the pipeline at this maschine. Just click on the quad in the middle and watch at the console.
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.nio.ByteBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLJPanel;
import javax.media.opengl.glu.GLU;
import javax.swing.JButton;
import javax.swing.JFrame;
import com.sun.opengl.util.BufferUtil;
public class PipelineError {
private static ByteBuffer mouseBuffer;
/**
* @param args
*/
public static void main(String[] args) {
GLCapabilities caps = new GLCapabilities();
caps.setAlphaBits(8);
final GLJPanel panel = new GLJPanel(caps);
panel.setOpaque(false);
panel.addGLEventListener(new GLEventListener() {
public void display(GLAutoDrawable arg0) {
GL gl = arg0.getGL();
if (panel.shouldPreserveColorBufferIfTranslucent()) {
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
} else {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glColor3f(0.6f, 0.6f,0.6f);
gl.glColor3f(1f, 0f, 1f);
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(-1, 1, 0);
gl.glVertex3f(-1, -1, 0);
gl.glVertex3f(1, -1, 0);
gl.glVertex3f(1, 1, 0);
gl.glEnd();
mouseBuffer = BufferUtil.newByteBuffer((panel.getWidth())
* (panel.getHeight()) * 4);
gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1);
gl.glReadPixels(0, 0, panel.getWidth(), panel.getHeight(), GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, mouseBuffer);
}
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
}
public void init(GLAutoDrawable arg0) {
arg0.getGL().glClearColor(1,0,1,0);
int clearBits = GL.GL_DEPTH_BUFFER_BIT;
clearBits |= GL.GL_COLOR_BUFFER_BIT;
arg0.getGL().glClear(clearBits);
}
public void reshape(GLAutoDrawable arg0, int x, int y, int width, int height) {
GL gl = arg0.getGL();
gl.glViewport(x, y, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
new GLU().gluPerspective(45.0, (float) width / height, 1.0, 400.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
new GLU().gluLookAt(
0,0,5, 0,0,0,
0, 1, 0);
}
});
panel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (mouseBuffer == null || x < 0 || y < 0) {
return;
}
int bufX = x;
int bufY = panel.getHeight() - y;
int pos = (bufY * panel.getWidth() + bufX) * 4;
if (pos >= 0 && pos < mouseBuffer.capacity()) {
int index = (mouseBuffer.get(pos + 3) & 0xFF);
System.out.println(index);
}
}
});
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.setGlassPane(panel);
panel.setVisible(true);
frame.add(new JButton("test-Button"), BorderLayout.CENTER);
frame.setVisible(true);
}
}