JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestGLOffscreenAutoDrawableBug1044AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 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.acore;
29
30import java.awt.image.BufferedImage;
31import java.io.File;
32import java.io.IOException;
33
34import javax.imageio.ImageIO;
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GL2;
37import com.jogamp.opengl.GLCapabilities;
38import com.jogamp.opengl.GLContext;
39import com.jogamp.opengl.GLDrawable;
40import com.jogamp.opengl.GLDrawableFactory;
41import com.jogamp.opengl.GLProfile;
42import com.jogamp.opengl.fixedfunc.GLLightingFunc;
43
44import org.junit.FixMethodOrder;
45import org.junit.Test;
46import org.junit.runners.MethodSorters;
47
48import com.jogamp.opengl.test.junit.util.UITestCase;
49import com.jogamp.opengl.util.GLReadBufferUtil;
50import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
51
52@FixMethodOrder(MethodSorters.NAME_ASCENDING)
54
55 @Test
56 public void test01GLOffscreenDrawable() throws InterruptedException {
57 final GLReadBufferUtil readBufferUtilRGB888 = new GLReadBufferUtil(false, false);
58 final GLReadBufferUtil readBufferUtilRGBA8888 = new GLReadBufferUtil(true, false);
61 // Without line below, there is an error on Windows.
62 glCap.setDoubleBuffered(false);
63 //makes a new buffer 100x100
64 final GLDrawable glad = fac.createOffscreenDrawable(null, glCap, null, 100, 100);
65 glad.setRealized(true);
66 final GLContext context = glad.createContext(null);
67 context.makeCurrent();
68
69 System.err.println("Chosen: "+glad.getChosenGLCapabilities());
70
71 final GL2 gl2 = context.getGL().getGL2();
72 gl2.glViewport(0, 0, 100, 100);
73
75 gl2.glClearColor(1.0f, 0.80f, 0.80f, 1); // This Will Clear The Background Color
76 gl2.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
78 gl2.glLoadIdentity(); // Reset The Projection Matrix
79
80 final AWTGLReadBufferUtil agb = new AWTGLReadBufferUtil(glad.getGLProfile(), true);
81 final BufferedImage image = agb.readPixelsToBufferedImage(context.getGL(), true);
82 try {
83 ImageIO.write(image, "PNG", new File(getSimpleTestName(".")+"-AWTImageIO.png"));
84 } catch (final IOException e) {
85 e.printStackTrace();
86 }
87
88 if(readBufferUtilRGB888.readPixels(gl2, false)) {
89 readBufferUtilRGB888.write(new File(getSimpleTestName(".")+"-PNGJ-rgb_.png"));
90 }
91 readBufferUtilRGB888.dispose(gl2);
92 if(readBufferUtilRGBA8888.readPixels(gl2, false)) {
93 readBufferUtilRGBA8888.write(new File(getSimpleTestName(".")+"-PNGJ-rgba.png"));
94 }
95 readBufferUtilRGBA8888.dispose(gl2);
96
97 context.destroy();
98 glad.setRealized(false);
99 System.out.println("Done!");
100 }
101
102 public static void main(final String[] args) {
103 org.junit.runner.JUnitCore.main(TestGLOffscreenAutoDrawableBug1044AWT.class.getName());
104 }
105}
106
Specifies a set of OpenGL capabilities.
void setDoubleBuffered(final boolean enable)
Enables or disables double buffering.
Abstraction for an OpenGL rendering context.
Definition: GLContext.java:74
abstract int makeCurrent()
Makes this GLContext current on the calling thread.
abstract void destroy()
Destroys this OpenGL context and frees its associated resources.
abstract GL getGL()
Returns the GL pipeline object for this GLContext.
abstract GLDrawable createOffscreenDrawable(AbstractGraphicsDevice device, GLCapabilitiesImmutable caps, GLCapabilitiesChooser chooser, int width, int height)
Creates an unrealized offscreen GLDrawable 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 getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
void write(final File dest)
Write the TextureData filled by readPixels(GLAutoDrawable, boolean) to file.
boolean readPixels(final GL gl, final boolean mustFlipVertically)
Read the drawable's pixels to TextureData and Texture, if requested at construction.
GLReadBufferUtil specialization allowing to read out a frambuffer to an AWT BufferedImage utilizing A...
BufferedImage readPixelsToBufferedImage(final GL gl, final boolean awtOrientation)
Read the drawable's pixels to TextureData and Texture, if requested at construction,...
void glClearDepth(double depth)
Aliased entrypoint of void {@native glClearDepth}(GLclampd depth); and void {@native glClearDepthf...
GL2 getGL2()
Casts this object to the GL2 interface.
An abstraction for an OpenGL rendering target.
Definition: GLDrawable.java:51
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
void setRealized(boolean realized)
Indicates to GLDrawable implementations whether the underlying surface has been created and can be dr...
GLContext createContext(GLContext shareWith)
Creates a new context for drawing to this drawable that will optionally share buffer objects,...
GLProfile getGLProfile()
Fetches the GLProfile for this drawable.
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,...
void glClear(int mask)
Entry point to C language function: void {@native glClear}(GLbitfield mask) Part of GL_ES_VERSION_...
void glViewport(int x, int y, int width, int height)
Entry point to C language function: void {@native glViewport}(GLint x, GLint y, GLsizei width,...
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
void glLoadIdentity()
Load the current matrix with the identity matrix.