1 package com.jogamp.opengl.test.junit.newt.parenting; 2 3 import java.io.IOException; 4 5 import com.jogamp.nativewindow.AbstractGraphicsDevice; 6 import com.jogamp.nativewindow.NativeWindow; 7 import com.jogamp.opengl.GLCapabilities; 8 import com.jogamp.opengl.GLCapabilitiesImmutable; 9 import com.jogamp.opengl.GLProfile; 10 11 import org.junit.Assert; 12 import org.junit.BeforeClass; 13 import org.junit.Test; 14 import org.junit.FixMethodOrder; 15 import org.junit.runners.MethodSorters; 16 17 import com.jogamp.newt.opengl.GLWindow; 18 import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; 19 import com.jogamp.opengl.test.junit.util.MiscUtils; 20 import com.jogamp.opengl.test.junit.util.UITestCase; 21 import com.jogamp.opengl.util.Animator; 22 23 @FixMethodOrder(MethodSorters.NAME_ASCENDING) 24 public class TestTranslucentChildWindowBug632NEWT extends UITestCase { 25 static long durationPerTest = 2*300; 26 static GLProfile glp; 27 static boolean opaque; 28 29 @BeforeClass initClass()30 public static void initClass() { 31 glp = GLProfile.getDefault(); 32 opaque = false; 33 } 34 createParentWindow(final GLCapabilitiesImmutable caps, final int width, final int height)35 static GLWindow createParentWindow(final GLCapabilitiesImmutable caps, final int width, final int height) 36 throws InterruptedException 37 { 38 Assert.assertNotNull(caps); 39 // 40 // Create native windowing resources .. X11/Win/OSX 41 // 42 GLWindow glWindow; 43 glWindow = GLWindow.create(caps); 44 Assert.assertNotNull(glWindow); 45 46 glWindow.setTitle("NEWT Parenting Window Test"); 47 48 glWindow.addGLEventListener(new GearsES2(1)); 49 50 glWindow.setSize(width, height); 51 glWindow.setVisible(true); 52 Assert.assertEquals(true,glWindow.isVisible()); 53 Assert.assertEquals(true,glWindow.isNativeValid()); 54 55 return glWindow; 56 } 57 createNestedWindow(final NativeWindow nativeParentWindow, final GLCapabilitiesImmutable caps, final int x, final int y, final int width, final int height)58 static GLWindow createNestedWindow(final NativeWindow nativeParentWindow, final GLCapabilitiesImmutable caps, final int x, final int y, final int width, final int height) 59 throws InterruptedException { 60 61 Assert.assertNotNull(nativeParentWindow); 62 Assert.assertNotNull(caps); 63 // 64 // Create native windowing resources .. X11/Win/OSX 65 // 66 GLWindow glWindow; 67 glWindow = GLWindow.create(nativeParentWindow, caps); 68 Assert.assertNotNull(glWindow); 69 70 glWindow.setTitle("NEWT Parenting Window Test"); 71 72 glWindow.addGLEventListener(new GearsES2(1)); 73 74 glWindow.setPosition(x, y); 75 glWindow.setSize(width, height); 76 glWindow.setVisible(true); 77 Assert.assertEquals(true,glWindow.isVisible()); 78 Assert.assertEquals(true,glWindow.isNativeValid()); 79 80 return glWindow; 81 } 82 destroyWindow(final GLWindow glWindow)83 static void destroyWindow(final GLWindow glWindow) { 84 if(null!=glWindow) { 85 glWindow.destroy(); 86 Assert.assertEquals(false,glWindow.isNativeValid()); 87 } 88 } 89 90 @Test testWindow00()91 public void testWindow00() throws InterruptedException { 92 final Animator animator = new Animator(); 93 94 final GLCapabilities caps = new GLCapabilities(glp); 95 Assert.assertNotNull(caps); 96 caps.setBackgroundOpaque(opaque); 97 final GLWindow window1 = createParentWindow(caps, 400, 400); 98 Assert.assertEquals(true,window1.isNativeValid()); 99 Assert.assertEquals(true,window1.isVisible()); 100 animator.add(window1); 101 102 final GLWindow window2 = createNestedWindow(window1, caps, 400-300, 400-300, 300, 300); 103 Assert.assertEquals(true,window2.isNativeValid()); 104 Assert.assertEquals(true,window2.isVisible()); 105 animator.add(window2); 106 107 animator.start(); 108 109 final AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); 110 111 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); 112 113 Thread.sleep(durationPerTest/2); 114 115 window1.setSize(512, 512); 116 window2.setPosition(512-300, 512-300); 117 118 Thread.sleep(durationPerTest/2); 119 120 animator.stop(); 121 122 destroyWindow(window2); 123 destroyWindow(window1); 124 } 125 main(final String[] args)126 public static void main(final String[] args) throws IOException { 127 for(int i=0; i<args.length; i++) { 128 if(args[i].equals("-time")) { 129 durationPerTest = MiscUtils.atol(args[++i], durationPerTest); 130 } 131 } 132 final String testName = TestTranslucentChildWindowBug632NEWT.class.getName(); 133 org.junit.runner.JUnitCore.main(testName); 134 } 135 } 136