29package com.jogamp.opengl.test.junit.jogl.util.texture;
32import com.jogamp.common.util.awt.AWTEDTExecutor;
33import com.jogamp.opengl.test.junit.jogl.demos.gl2.TextureDraw01GL2Listener;
34import com.jogamp.opengl.test.junit.util.MiscUtils;
35import com.jogamp.opengl.test.junit.util.UITestCase;
37import com.jogamp.opengl.GLAutoDrawable;
38import com.jogamp.opengl.GLEventListener;
39import com.jogamp.opengl.GLProfile;
40import com.jogamp.opengl.GLCapabilities;
41import com.jogamp.opengl.awt.GLCanvas;
42import javax.swing.ImageIcon;
43import javax.swing.JLabel;
45import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;
46import com.jogamp.opengl.util.texture.TextureData;
47import com.jogamp.opengl.util.texture.awt.AWTTextureIO;
49import java.awt.AlphaComposite;
50import java.awt.Canvas;
53import java.awt.GradientPaint;
54import java.awt.Graphics2D;
55import java.awt.image.BufferedImage;
57import java.io.IOException;
58import org.junit.Assert;
59import org.junit.After;
60import org.junit.Assume;
61import org.junit.Before;
62import org.junit.BeforeClass;
64import org.junit.FixMethodOrder;
65import org.junit.runners.MethodSorters;
73@FixMethodOrder(MethodSorters.NAME_ASCENDING)
75 static long durationPerTest = 500;
78 BufferedImage textureImage;
87 Assert.assertNotNull(glp);
89 Assert.assertNotNull(caps);
95 BufferedImage baseImage =
new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR);
96 Assert.assertNotNull(baseImage);
97 Graphics2D g = baseImage.createGraphics();
98 Assert.assertNotNull(g);
99 g.setPaint(
new GradientPaint(0, 0, Color.CYAN,
100 baseImage.getWidth(), baseImage.getHeight(), Color.BLUE));
101 g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight());
105 final int imageType = BufferedImage.TYPE_3BYTE_BGR;
106 textureImage =
new BufferedImage(baseImage.getWidth(),
107 baseImage.getHeight(),
109 Assert.assertNotNull(textureImage);
110 g = textureImage.createGraphics();
111 g.setComposite(AlphaComposite.Src);
112 g.drawImage(baseImage, 0, 0,
null);
121 Assert.assertNotNull(textureImage);
122 textureImage.flush();
127 public void test1() throws InterruptedException {
129 final Frame frame0 =
new Frame(
"GL -> AWT");
130 final Canvas canvas =
new Canvas();
134 final Frame frame1 =
new Frame(
"AWT -> Texture");
135 Assert.assertNotNull(frame1);
136 frame1.add(glCanvas);
150 final ImageIcon imageIcon =
new ImageIcon(outputImage);
151 final JLabel imageLabel =
new JLabel(imageIcon);
153 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
156 frame0.add(imageLabel);
159 }
catch (
final Exception e) {
165 public void reshape(
final GLAutoDrawable drawable,
final int x,
final int y,
final int width,
final int height) {
166 frame0.setSize(frame1.getWidth(), frame1.getHeight());
167 frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
173 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
175 frame1.setSize(256, 256);
176 frame1.setLocation(0, 0);
177 frame1.setVisible(
true);
178 frame0.setSize(frame1.getWidth(), frame1.getHeight());
179 frame0.setLocation(frame1.getX()+frame1.getWidth()+32, frame0.getY());
180 frame0.setVisible(
true);
182 }
catch(
final Throwable throwable ) {
183 throwable.printStackTrace();
184 Assume.assumeNoException( throwable );
187 Thread.sleep(durationPerTest);
190 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
192 frame0.setVisible(
false);
194 frame1.setVisible(
false);
197 }
catch(
final Throwable throwable ) {
198 throwable.printStackTrace();
199 Assume.assumeNoException( throwable );
203 public static void main(
final String args[])
throws IOException {
204 for(
int i=0; i<args.length; i++) {
205 if(args[i].equals(
"-time")) {
206 durationPerTest =
MiscUtils.
atol(args[++i], durationPerTest);
210 org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.
main(
new String[] {
214 "haltOnFailure=false",
216 "outputtoformatters=true",
217 "logfailedtests=true",
218 "logtestlistenerevents=true",
219 "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
220 "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+
".xml" } );
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.
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
static final String GL2GL3
The intersection of the desktop GL3 and GL2 profile.
A heavyweight AWT component which provides OpenGL rendering support.
void addGLEventListener(final GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Demonstrates TextureData w/ AWT usage in both directions, i.e.
static void main(final String args[])
static long atol(final String str, final long def)
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,...
Represents the data for an OpenGL texture.
static TextureData newTextureData(final GLProfile glp, final BufferedImage image, final boolean mipmap)
Creates a TextureData from the given BufferedImage.
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.