1 package com.jogamp.opengl.test.junit.newt; 2 3 import java.io.IOException; 4 5 import com.jogamp.nativewindow.AbstractGraphicsDevice; 6 import com.jogamp.opengl.GLCapabilities; 7 import com.jogamp.opengl.GLCapabilitiesImmutable; 8 import com.jogamp.opengl.GLEventListener; 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.Screen; 18 import com.jogamp.newt.opengl.GLWindow; 19 import com.jogamp.opengl.test.junit.jogl.demos.es1.GearsES1; 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 TestGLWindowInvisiblePointer01NEWT extends UITestCase { 25 static GLProfile glp; 26 static int width, height; 27 static long durationPerTest = 4000; // ms 28 29 @BeforeClass initClass()30 public static void initClass() { 31 width = 640; 32 height = 480; 33 glp = GLProfile.getDefault(); 34 } 35 createWindow(final Screen screen, final GLCapabilitiesImmutable caps)36 static GLWindow createWindow(final Screen screen, final GLCapabilitiesImmutable caps) 37 throws InterruptedException 38 { 39 Assert.assertNotNull(caps); 40 // 41 // Create native windowing resources .. X11/Win/OSX 42 // 43 GLWindow glWindow; 44 if(null!=screen) { 45 glWindow = GLWindow.create(screen, caps); 46 Assert.assertNotNull(glWindow); 47 } else { 48 glWindow = GLWindow.create(caps); 49 Assert.assertNotNull(glWindow); 50 } 51 glWindow.setUpdateFPSFrames(1, null); 52 53 final GLEventListener demo = new GearsES1(); 54 glWindow.addGLEventListener(demo); 55 56 glWindow.setSize(512, 512); 57 glWindow.setVisible(true); 58 Assert.assertEquals(true,glWindow.isVisible()); 59 Assert.assertEquals(true,glWindow.isNativeValid()); 60 61 return glWindow; 62 } 63 destroyWindow(final GLWindow glWindow)64 static void destroyWindow(final GLWindow glWindow) { 65 if(null!=glWindow) { 66 glWindow.destroy(); 67 Assert.assertEquals(false,glWindow.isNativeValid()); 68 } 69 } 70 71 @Test testWindow00()72 public void testWindow00() throws InterruptedException { 73 final GLCapabilities caps = new GLCapabilities(glp); 74 Assert.assertNotNull(caps); 75 final GLWindow window1 = createWindow(null, caps); // local 76 Assert.assertEquals(true,window1.isNativeValid()); 77 Assert.assertEquals(true,window1.isVisible()); 78 final Animator animator = new Animator(); 79 animator.setUpdateFPSFrames(1, null); 80 animator.add(window1); 81 animator.start(); 82 final AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); 83 84 System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); 85 86 window1.warpPointer(width / 2, height / 2); 87 window1.requestFocus(); 88 while(animator.isAnimating() && animator.getTotalFPSDuration()<durationPerTest) { 89 final boolean pointerVisibleNewVal = (animator.getTotalFPSDuration()/100)%2==0; 90 window1.setPointerVisible(pointerVisibleNewVal); 91 Assert.assertEquals(pointerVisibleNewVal,window1.isPointerVisible()); 92 Thread.sleep(100); 93 } 94 95 destroyWindow(window1); 96 } 97 atoi(final String a)98 static int atoi(final String a) { 99 int i=0; 100 try { 101 i = Integer.parseInt(a); 102 } catch (final Exception ex) { ex.printStackTrace(); } 103 return i; 104 } 105 main(final String args[])106 public static void main(final String args[]) throws IOException { 107 for(int i=0; i<args.length; i++) { 108 if(args[i].equals("-time")) { 109 durationPerTest = atoi(args[++i]); 110 } 111 } 112 System.out.println("durationPerTest: "+durationPerTest); 113 final String tstname = TestGLWindowInvisiblePointer01NEWT.class.getName(); 114 org.junit.runner.JUnitCore.main(tstname); 115 } 116 117 } 118