JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestTexture02AWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2010 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 */
28
29package com.jogamp.opengl.test.junit.jogl.util.texture;
30
31
32import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
33import com.jogamp.opengl.test.junit.util.MiscUtils;
34import com.jogamp.opengl.test.junit.util.UITestCase;
35
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLEventListener;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.GLCapabilities;
40import com.jogamp.opengl.awt.GLCanvas;
41import javax.swing.ImageIcon;
42import javax.swing.JLabel;
43
44import com.jogamp.opengl.util.FPSAnimator;
45import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
46
47import java.awt.Frame;
48import java.awt.image.BufferedImage;
49
50import java.io.IOException;
51import org.junit.Assert;
52import org.junit.Assume;
53import org.junit.BeforeClass;
54import org.junit.Test;
55import org.junit.FixMethodOrder;
56import org.junit.runners.MethodSorters;
57
58/**
59 * Demonstrates TextureData w/ AWT usage,
60 * i.e. reading out an animated GL framebuffer and displaying it
61 * as an BufferedImage.
62 */
63@FixMethodOrder(MethodSorters.NAME_ASCENDING)
64public class TestTexture02AWT extends UITestCase {
65 static long durationPerTest = 500;
66 static GLProfile glp;
67 static GLCapabilities caps;
68
69 @BeforeClass
70 public static void initClass() {
72 UITestCase.setTestSupported(false);
73 return;
74 }
75 glp = GLProfile.getGL2ES2();
76 Assert.assertNotNull(glp);
77 caps = new GLCapabilities(glp);
78 Assert.assertNotNull(caps);
79 }
80
81 @Test
82 public void test1() throws InterruptedException {
83 final AWTGLReadBufferUtil awtGLReadBufferUtil = new AWTGLReadBufferUtil(caps.getGLProfile(), false);
84 final Frame frame0 = new Frame("GL -> AWT");
85 final ImageIcon imageIcon = new ImageIcon();
86 final JLabel imageLabel = new JLabel(imageIcon);
87 frame0.add(imageLabel);
88
89 final GLCanvas glCanvas = new GLCanvas(caps);
90 final Frame frame1 = new Frame("GearsES2");
91 Assert.assertNotNull(frame1);
92 frame1.add(glCanvas);
93
94 glCanvas.addGLEventListener(new GearsES2(1));
95 glCanvas.addGLEventListener(new GLEventListener() {
96 @Override
97 public void init(final GLAutoDrawable drawable) { }
98 @Override
99 public void dispose(final GLAutoDrawable drawable) { }
100 @Override
101 public void display(final GLAutoDrawable drawable) {
102 final BufferedImage outputImage = awtGLReadBufferUtil.readPixelsToBufferedImage(drawable.getGL(), true /* awtOrientation */);
103 imageIcon.setImage(outputImage);
104 imageLabel.repaint();
105 }
106
107 @Override
108 public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
109 frame0.setSize(frame1.getWidth(), frame1.getHeight());
110 frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
111 frame0.validate();
112 }
113 });
114
115 try {
116 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
117 public void run() {
118 frame1.setSize(256, 256);
119 frame1.setLocation(0, 0);
120 frame1.setVisible(true);
121 frame0.setSize(frame1.getWidth(), frame1.getHeight());
122 frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
123 frame0.setVisible(true);
124 }});
125 } catch( final Throwable throwable ) {
126 throwable.printStackTrace();
127 Assume.assumeNoException( throwable );
128 }
129 final FPSAnimator animator = new FPSAnimator(glCanvas, 15); // 15fps
130 animator.start();
131
132 Thread.sleep(durationPerTest);
133
134 animator.stop();
135 try {
136 javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
137 public void run() {
138 frame0.setVisible(false);
139 frame0.dispose();
140 frame1.setVisible(false);
141 frame1.dispose();
142 }});
143 } catch( final Throwable throwable ) {
144 throwable.printStackTrace();
145 Assume.assumeNoException( throwable );
146 }
147 }
148
149 public static void main(final String args[]) throws IOException {
150 for(int i=0; i<args.length; i++) {
151 if(args[i].equals("-time")) {
152 durationPerTest = MiscUtils.atol(args[++i], durationPerTest);
153 }
154 }
155 final String tstname = TestTexture02AWT.class.getName();
156 org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
157 tstname,
158 "filtertrace=true",
159 "haltOnError=false",
160 "haltOnFailure=false",
161 "showoutput=true",
162 "outputtoformatters=true",
163 "logfailedtests=true",
164 "logtestlistenerevents=true",
165 "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
166 "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
167 }
168}
Specifies a set of OpenGL capabilities.
final GLProfile getGLProfile()
Returns the GL profile you desire or used by the drawable.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
A heavyweight AWT component which provides OpenGL rendering support.
Definition: GLCanvas.java:170
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Definition: GLCanvas.java:1065
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
An Animator subclass which attempts to achieve a target frames-per-second rate to avoid using all CPU...
final synchronized boolean start()
Starts this animator, if not running.
final synchronized boolean stop()
Stops this FPSAnimator.
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,...
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.