/** * Copyright 2011 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of JogAmp Community. */ import java.awt.image.BufferedImage; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; import javax.media.opengl.GLPbuffer; import javax.media.opengl.GLProfile; import com.jogamp.opengl.util.awt.Screenshot; public class FlippedImageTest implements GLEventListener { GLPbuffer glPBuffer = null; public FlippedImageTest() { GLProfile glp = GLProfile.get(GLProfile.GL2); GLCapabilities caps = new GLCapabilities(glp); GLDrawableFactory glFactory = GLDrawableFactory.getFactory(glp); caps.setAccumRedBits(16); caps.setAccumGreenBits(16); caps.setAccumBlueBits(16); caps.setStencilBits(8); caps.setDoubleBuffered(true); caps.setHardwareAccelerated(true); try { glPBuffer = glFactory.createGLPbuffer(null, caps, null, 4, 4, null); } catch (GLException exc) { } glPBuffer.addGLEventListener(this); } /** * @param args */ public static void main(String[] args) { FlippedImageTest demo = new FlippedImageTest(); demo.glPBuffer.display(); demo.glPBuffer.createContext(null).makeCurrent(); BufferedImage image = Screenshot.readToBufferedImage(4, 4); int above = image.getRGB(0, 0); int below = image.getRGB(0, 3); if (above == 0xff00ff00 && below == 0xffff0000) { System.out.println("image right side up"); } else if (above == 0xffff0000 && below == 0xff00ff00) { System.out.println("image is flipped"); } else { System.out.println("error in test"); } } public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); // red below gl.glColor3f(1, 0, 0); gl.glRectf(-1, -1, 1, 0); // green above gl.glColor3f(0, 1, 0); gl.glRectf(-1, 0, 1, 1); gl.glFinish(); gl.glAccum(GL2.GL_ACCUM, 1.0f); gl.glAccum(GL2.GL_RETURN, 1.0f); gl.glEnd(); gl.glFlush(); } public void init(GLAutoDrawable drawable) { } public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) { } public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { } public void dispose(GLAutoDrawable drawable) { } }