JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestBug605FlippedImageNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.jogl.caps;
29
30import java.nio.ByteBuffer;
31
32import com.jogamp.opengl.GL;
33import com.jogamp.opengl.GL2;
34import com.jogamp.opengl.GLAutoDrawable;
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLCapabilitiesImmutable;
37import com.jogamp.opengl.GLDrawableFactory;
38import com.jogamp.opengl.GLEventListener;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
41
42import org.junit.Assert;
43import org.junit.Test;
44import org.junit.FixMethodOrder;
45import org.junit.runners.MethodSorters;
46
47import com.jogamp.opengl.test.junit.util.UITestCase;
48import com.jogamp.opengl.util.GLReadBufferUtil;
49
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
52 static class FlippedImageTest implements GLEventListener {
53 public void display(final GLAutoDrawable drawable) {
54 final GL2 gl = drawable.getGL().getGL2();
55
56 gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
58
60 gl.glLoadIdentity();
62 gl.glLoadIdentity();
63
64 // red below
65 gl.glColor3f(1, 0, 0);
66 gl.glRectf(-1, -1, 1, 0);
67
68 // green above
69 gl.glColor3f(0, 1, 0);
70 gl.glRectf(-1, 0, 1, 1);
71 gl.glFinish();
72
74 if(caps.getAccumGreenBits() > 0) {
75 gl.glAccum(GL2.GL_ACCUM, 1.0f);
76 gl.glAccum(GL2.GL_RETURN, 1.0f);
77 }
78 gl.glFinish();
79 }
80
81 public void init(final GLAutoDrawable drawable) {
82 final GL gl = drawable.getGL();
83 System.err.println("GL_RENDERER: "+gl.glGetString(GL.GL_RENDERER));
84 System.err.println("GL_VERSION: "+gl.glGetString(GL.GL_VERSION));
85 }
86 public void reshape(final GLAutoDrawable glDrawable, final int x, final int y, final int w, final int h) {}
87 public void displayChanged(final GLAutoDrawable drawable, final boolean modeChanged, final boolean deviceChanged) {}
88 public void dispose(final GLAutoDrawable drawable) {}
89 }
90
91 static final int green = 0x0000ff00; // above
92 static final int red = 0x00ff0000; // below
93
94 private int getRGB(final ByteBuffer bb, final int o) {
95 return ( bb.get(o+0) & 0x000000ff ) << 16 |
96 ( bb.get(o+1) & 0x000000ff ) << 8 |
97 ( bb.get(o+2) & 0x000000ff );
98 }
99
100 private void testFlipped(final ByteBuffer bb, final int width, final int height, final int comp) {
101 // Default origin 0/0 is lower left corner, so is the memory layout
102
103 // x=0, y=0: RGB -> _RGB [high-byte .. low-byte]
104 final int below = getRGB(bb, 0);
105 System.err.println("below: 0x"+Integer.toHexString(below));
106
107 // x=0, y=height-1: RGB -> _RGB [high-byte .. low-byte]
108 final int above= getRGB(bb, ( height - 1 ) * ( width * comp ));
109 System.err.println("above: 0x"+Integer.toHexString(above));
110
111 if (above == green && below == red) {
112 System.out.println("Image right side up");
113 } else if (above == red && below == green) {
114 Assert.assertTrue("Image is flipped", false);
115 } else {
116 Assert.assertTrue("Error in test", false);
117 }
118 }
119
120 private void test(final GLCapabilitiesImmutable caps) {
121 final GLReadBufferUtil rbu = new GLReadBufferUtil(false, false);
123 final GLAutoDrawable glad = glFactory.createOffscreenAutoDrawable(null, caps, null, 256, 256);
124 final FlippedImageTest tglel = new FlippedImageTest();
125 glad.addGLEventListener(tglel);
127 glad.addGLEventListener(snap);
128 snap.setMakeSnapshotAlways(true);
129
130 // 1 frame incl. snapshot to memory & file
131 glad.display();
132 System.err.println("XXX "+glad.getChosenGLCapabilities());
133 System.err.println("XXX "+glad.getContext().getGLVersion());
134 testFlipped((ByteBuffer)rbu.getPixelBuffer().buffer, glad.getSurfaceWidth(), glad.getSurfaceHeight(), 3);
135
136 glad.destroy();
137 }
138
139 @Test
140 public void test01DefaultFBO() {
141 final GLProfile glp = GLProfile.get(GLProfile.GL2);
142 final GLCapabilities caps = new GLCapabilities(glp);
143 caps.setFBO(true);
144 test(caps);
145 }
146
147 @Test
148 public void test01StencilFBO() {
149 final GLProfile glp = GLProfile.get(GLProfile.GL2);
150 final GLCapabilities caps = new GLCapabilities(glp);
151 caps.setStencilBits(8);
152 caps.setFBO(true);
153 test(caps);
154 }
155
156 @Test
157 public void test01DefaultPBuffer() {
158 final GLProfile glp = GLProfile.get(GLProfile.GL2);
159 final GLCapabilities caps = new GLCapabilities(glp);
160 caps.setPBuffer(true);
161 test(caps);
162 }
163
164 @Test
166 final GLProfile glp = GLProfile.get(GLProfile.GL2);
167 final GLCapabilities caps = new GLCapabilities(glp);
168 caps.setAccumRedBits(16);
169 caps.setAccumGreenBits(16);
170 caps.setAccumBlueBits(16);
171 caps.setStencilBits(8);
172 caps.setPBuffer(true);
173 test(caps);
174 }
175
176 public static void main(final String[] args) {
177 org.junit.runner.JUnitCore.main(TestBug605FlippedImageNEWT.class.getName());
178 }
179}
Specifies a set of OpenGL capabilities.
void setPBuffer(final boolean enable)
Requesting offscreen pbuffer mode.
void setAccumRedBits(final int accumRedBits)
Sets the number of bits requested for the accumulation buffer's red component.
void setStencilBits(final int stencilBits)
Sets the number of bits requested for the stencil buffer.
void setAccumGreenBits(final int accumGreenBits)
Sets the number of bits requested for the accumulation buffer's green component.
void setFBO(final boolean enable)
Requesting offscreen FBO mode.
void setAccumBlueBits(final int accumBlueBits)
Sets the number of bits requested for the accumulation buffer's blue component.
final String getGLVersion()
Returns a valid OpenGL version string, ie
Definition: GLContext.java:769
abstract GLOffscreenAutoDrawable createOffscreenAutoDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates a realized GLOffscreenAutoDrawable incl it's offscreen NativeSurface with the given capabilit...
static GLDrawableFactory getFactory(final GLProfile glProfile)
Returns the sole GLDrawableFactory instance.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile get(final AbstractGraphicsDevice device, String profile)
Returns a GLProfile object.
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
final Buffer buffer
Buffer holding the pixel data.
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
GLPixelBuffer getPixelBuffer()
Returns the GLPixelBuffer, created and filled by readPixels(GLAutoDrawable, boolean).
static final int GL_ACCUM_BUFFER_BIT
GL_VERSION_1_0 Define "GL_ACCUM_BUFFER_BIT" with expression '0x00000200', CType: int
Definition: GL2.java:1547
static final int GL_ACCUM
GL_VERSION_1_0 Define "GL_ACCUM" with expression '0x0100', CType: int
Definition: GL2.java:2164
static final int GL_RETURN
GL_VERSION_1_0 Define "GL_RETURN" with expression '0x0102', CType: int
Definition: GL2.java:1413
void glAccum(int op, float value)
Entry point to C language function: void {@native glAccum}(GLenum op, GLfloat value) Part of GL_VE...
void glColor3f(float red, float green, float blue)
Entry point to C language function: void {@native glColor3f}(GLfloat red, GLfloat green,...
void glRectf(float x1, float y1, float x2, float y2)
Entry point to C language function: void {@native glRectf}(GLfloat x1, GLfloat y1,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
GLContext getContext()
Returns the context associated with this drawable.
GL2 getGL2()
Casts this object to the GL2 interface.
Specifies an immutable set of OpenGL capabilities.
int getAccumGreenBits()
Returns the number of bits for the accumulation buffer's green component.
GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.
static final int GL_VERSION
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_VERSION" with express...
Definition: GL.java:190
static final int GL_COLOR_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_COLOR_BUFFER_BIT" wit...
Definition: GL.java:390
void glClearColor(float red, float green, float blue, float alpha)
Entry point to C language function: void {@native glClearColor}(GLfloat red, GLfloat green,...
String glGetString(int name)
Entry point to C language function: const GLubyte * {@native glGetString}(GLenum name) Part of GL_...
static final int GL_RENDERER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RENDERER" with expres...
Definition: GL.java:662
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glFinish()
Entry point to C language function: void {@native glFinish}() Part of GL_ES_VERSION_2_0,...
static final int GL_STENCIL_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_STENCIL_BUFFER_BIT" w...
Definition: GL.java:60
static final int GL_DEPTH_BUFFER_BIT
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_DEPTH_BUFFER_BIT" wit...
Definition: GL.java:738
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW
Matrix mode modelview.
void glLoadIdentity()
Load the current matrix with the identity matrix.
void glMatrixMode(int mode)
Sets the current matrix mode.