no glReadPixels on OS X?

I can’t do a glReadPixels on Mac OS X with the latest nightly build of JOGL. If I use my old jars/jnilibs it works fine. I don’t get back any pixels from the current builds. Does anybody have any clues about this? Is it a driver bug, a JOGL bug, or am I doing something wrong?

Thanks!

Corwin

Have you tried using Gerard’s Jogl build (updated on the 20th June 04)?

http://homepage.mac.com/gziemski/projects/

No, but I am running off of the HEAD of the jogl cvs repository. As far as I know he just builds the jogl source- there’s no specific changes he makes that aren’t in the source tree, right?

My suspicion is that it’s a driver bug, but that’s hard to verify. I guess I should write a C app that checks.

Corwin

Have you got a sample test case code scenario to show (so that I could test on my machine for you, to make sure it’s not a problem with your environment)?

Check it.

A roughly analagous Obj-C solution works fine. Let me know if I’m just doing something stupid (I hope) :slight_smile:

Corwin

import net.java.games.jogl.*;

import javax.swing.;
import javax.imageio.ImageIO;
import java.awt.image.
;
import java.io.File;

public class JReadPixelsTest extends JFrame implements GLEventListener {
GLCanvas canvas = null;

public static void main(String[] args) {
    JReadPixelsTest frame = new JReadPixelsTest();

    frame.setBounds(0, 0, 480, 360);
    frame.show();
}

JReadPixelsTest() {
    canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
    this.getContentPane().add(canvas);
    canvas.addGLEventListener(this);
}

public void init(GLDrawable drawable)
{

}

public void display(GLDrawable drawable)
{
    GL gl = drawable.getGL();
    GLU glu = drawable.getGLU();

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluOrtho2D(0, 480, 0, 360);

    gl.glBegin(GL.GL_QUADS); {
        gl.glColor4d(1.0, 0.0, 0.0, 1.0);
        gl.glVertex2d(50.0, 50.0);
        gl.glVertex2d(430.0, 50.0);
        gl.glVertex2d(430.0, 310.0);
        gl.glVertex2d(50.0, 310.0);
    } gl.glEnd();

    gl.glFlush();

    SwingUtilities.invokeLater(new Runnable() { public void run() { saveAJpeg(); } });
}

public void reshape(GLDrawable drawable, int x, int y, int width, int height)
{

}

public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
{

}

public void saveAJpeg()
{
    GL gl = canvas.getGL();

    gl.glReadBuffer(GL.GL_BACK);
    BufferedImage imageBack = new BufferedImage(480, 360, BufferedImage.TYPE_INT_ARGB);
    DataBufferInt awfulBufferBack = (DataBufferInt) imageBack.getRaster().getDataBuffer();

    gl.glReadPixels(0, 0, 480, 360, GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, awfulBufferBack.getData());
    gl.glFinish();

    try {
        ImageIO.write(imageBack, "jpeg", new File("/tmp/JReadPixelsTestBack.jpeg"));
    } catch (Exception e) {
        System.err.println("I am an exception, hear me roar????");
    }

    gl.glReadBuffer(GL.GL_FRONT);
    BufferedImage imageFront = new BufferedImage(480, 360, BufferedImage.TYPE_INT_ARGB);
    DataBufferInt awfulBufferFront = (DataBufferInt) imageFront.getRaster().getDataBuffer();

    gl.glReadPixels(0, 0, 480, 360, GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, awfulBufferFront.getData());
    gl.glFinish();

    try {
        ImageIO.write(imageFront, "jpeg", new File("/tmp/JReadPixelsTestFront.jpeg"));
    } catch (Exception e) {
        System.err.println("I am an exception, hear me roar????");
    }
}

}

If you do:

saveAJpeg()

directly, instead of:

SwingUtilities.invokeLater(new Runnable() { public void run() { saveAJpeg(); } });

does it work for you? It seems to work for me, don’t know yet why that works and why the original code doesn’t work.

Also, not directly related to the problem at hand, but there is a pixel layout mismatch: the gl buffers are in GL.GL_RGBA, but your BufferedImage is in BufferedImage.TYPE_INT_ARGB - alpha is in wrong place.

cheers

Yes, the problem was that you can only make GL calls inside one of the GLEventListener methods. My mistake!

Corwin