29package com.jogamp.opengl.test.junit.jogl.caps;
31import java.awt.BorderLayout;
33import java.awt.Container;
34import java.awt.Dimension;
36import java.awt.GraphicsConfiguration;
37import java.awt.GraphicsDevice;
38import java.awt.GraphicsEnvironment;
40import java.awt.Transparency;
41import java.awt.image.ColorModel;
42import java.io.IOException;
43import java.lang.reflect.InvocationTargetException;
45import com.jogamp.opengl.GLAnimatorControl;
46import com.jogamp.opengl.GLCapabilities;
47import com.jogamp.opengl.GLEventListener;
48import com.jogamp.opengl.awt.GLCanvas;
50import org.junit.Assert;
51import org.junit.BeforeClass;
53import org.junit.FixMethodOrder;
54import org.junit.runners.MethodSorters;
56import com.jogamp.common.util.ReflectionUtil;
57import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
58import com.jogamp.opengl.test.junit.util.UITestCase;
59import com.jogamp.opengl.util.Animator;
61@FixMethodOrder(MethodSorters.NAME_ASCENDING)
63 static Dimension size;
64 static long durationPerTest = 400;
69 size =
new Dimension(400,200);
74 static Frame getTranslucentFrame() {
75 GraphicsConfiguration gc=
null;
76 final GraphicsDevice[] devices= GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
77 for (
int i = 0; i < devices.length ; i++)
79 final GraphicsConfiguration[] configs = devices[i].getConfigurations();
80 for (
int j = 0; j < configs.length ; j++) {
81 final GraphicsConfiguration config = configs[j];
82 final ColorModel tcm = config.getColorModel(Transparency.TRANSLUCENT);
83 final boolean capable1 = (
null != tcm ) ? tcm.getTransparency() == Transparency.TRANSLUCENT :
false;
84 boolean capable2 =
false;
86 capable2 = ((Boolean)ReflectionUtil.callStaticMethod(
87 "com.sun.awt.AWTUtilities",
"isTranslucencyCapable",
88 new Class<?>[] { GraphicsConfiguration.class },
89 new Object[] { config } ,
90 GraphicsConfiguration.class.getClassLoader())).booleanValue();
91 System.err.println(
"com.sun.awt.AWTUtilities.isTranslucencyCapable(config) passed: "+capable2);
92 }
catch (
final RuntimeException re) {
93 System.err.println(
"com.sun.awt.AWTUtilities.isTranslucencyCapable(config) failed: "+re.getMessage());
95 System.err.println(i+
":"+j+
" "+config+
", "+tcm+
", capable "+capable1+
"/"+capable2);
96 if(capable1&&capable2) {
98 System.err.println(
"Chosen "+i+
":"+j+
" "+config+
", "+tcm+
", capable "+capable1+
"/"+capable2);
103 final Frame frame =
new Frame(gc);
105 frame.setUndecorated(
true);
106 frame.setBackground(
new Color(0, 0, 0, 0));
108 frame.setTitle(
"AWT Parent Frame (opaque: "+(
null==gc)+
")");
113 public void test() throws InterruptedException, InvocationTargetException {
114 final Frame frame1 = getTranslucentFrame();
117 glCanvas.setPreferredSize(size);
125 final Container cont1 =
new Container();
126 cont1.setLayout(
new BorderLayout());
127 cont1.add(glCanvas, BorderLayout.CENTER);
128 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
130 cont1.setVisible(
true);
133 frame1.setLayout(
new BorderLayout());
134 frame1.add(cont1, BorderLayout.EAST);
135 frame1.add(
new Label(
"center"), BorderLayout.CENTER);
136 javax.swing.SwingUtilities.invokeAndWait(
new Runnable() {
138 frame1.setLocation(0, 0);
139 frame1.setSize((
int)size.getWidth(), (
int)size.getHeight());
141 frame1.setVisible(
true);
144 Assert.assertEquals(
true, animator1.
isAnimating());
145 Assert.assertEquals(
false, animator1.
isPaused());
146 Assert.assertNotNull(animator1.
getThread());
148 Thread.sleep(durationPerTest);
151 Assert.assertEquals(
false, animator1.
isAnimating());
152 Assert.assertEquals(
false, animator1.
isPaused());
153 Assert.assertEquals(
null, animator1.
getThread());
158 static int atoi(
final String a) {
161 i = Integer.parseInt(a);
162 }
catch (
final Exception ex) { ex.printStackTrace(); }
166 public static void main(
final String args[])
throws IOException {
167 for(
int i=0; i<args.length; i++) {
168 if(args[i].equals(
"-time")) {
169 durationPerTest = atoi(args[++i]);
173 org.junit.runner.JUnitCore.
main(tstname);
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
Specifies a set of OpenGL capabilities.
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.
static void main(final String args[])
An animator control interface, which implementation may drive a com.jogamp.opengl....
boolean start()
Starts this animator, if not running.
boolean isPaused()
Indicates whether this animator is started and either manually paused or paused automatically due to ...
boolean isAnimating()
Indicates whether this animator is started and is not paused.
boolean stop()
Stops this animator.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.