@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] urls0 = new String[] { System.getProperty("jnlp.media0_url2"), System.getProperty("jnlp.media0_url1"), System.getProperty("jnlp.media0_url0") }; final URLConnection urlConnection0 = getResource(urls0, 0); if (null == urlConnection0) { throw new RuntimeException("no media reachable: " + Arrays.asList(urls0)); } // also initializes JOGL final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2()); capsMain.setBackgroundOpaque(false); // screen for layout params .. final com.jogamp.newt.Display dpy = NewtFactory.createDisplay(null); final com.jogamp.newt.Screen scrn = NewtFactory.createScreen(dpy, 0); scrn.addReference(); try { final Animator animator = new Animator(); // Main final MovieCube demoMain = new MovieCube( urlConnection0, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, -2.3f, 0f, 0f); final GLWindow glWindowMain = GLWindow.create(scrn, capsMain); glWindowMain.setFullscreen(true); setContentView(getWindow(), glWindowMain); glWindowMain.addMouseListener(showKeyboardMouseListener); glWindowMain.addGLEventListener(demoMain); animator.add(glWindowMain); glWindowMain.setVisible(true); // animator.setUpdateFPSFrames(60, System.err); animator.setUpdateFPSFrames(-1, null); animator.resetFPSCounter(); } catch (IOException e) { e.printStackTrace(); } scrn.removeReference(); Log.d(TAG, "onCreate - X"); }
static Window createWindow( final Capabilities caps, final int x, final int y, final int width, final int height, final boolean onscreen, final boolean undecorated) throws InterruptedException { final boolean userPos = x >= 0 && y >= 0; // user has specified a position Assert.assertNotNull(caps); caps.setOnscreen(onscreen); // System.out.println("Requested: "+caps); // // Create native windowing resources .. X11/Win/OSX // final Window window = NewtFactory.createWindow(caps); Assert.assertNotNull(window); final Screen screen = window.getScreen(); final Display display = screen.getDisplay(); window.setUndecorated(onscreen && undecorated); if (userPos) { window.setPosition(x, y); } window.setSize(width, height); Assert.assertEquals(false, window.isNativeValid()); Assert.assertEquals(false, window.isVisible()); window.setVisible(true); // System.err.println("************* Created: "+window); Assert.assertEquals(true, display.isNativeValid()); Assert.assertEquals(true, screen.isNativeValid()); Assert.assertEquals(true, window.isVisible()); Assert.assertEquals(true, window.isNativeValid()); Assert.assertEquals(width, window.getWidth()); Assert.assertEquals(height, window.getHeight()); /** * we don't sync on position - unreliable test Point p0 = window.getLocationOnScreen(null); * Assert.assertEquals(p0.getX(), window.getX()); Assert.assertEquals(p0.getY(), window.getY()); * if(userPos) { Assert.assertEquals(x, window.getX()); Assert.assertEquals(y, window.getY()); } */ final CapabilitiesImmutable chosenCapabilities = window.getGraphicsConfiguration().getChosenCapabilities(); Assert.assertNotNull(chosenCapabilities); Assert.assertTrue(chosenCapabilities.getGreenBits() >= 5); Assert.assertTrue(chosenCapabilities.getBlueBits() >= 5); Assert.assertTrue(chosenCapabilities.getRedBits() >= 5); Assert.assertEquals(chosenCapabilities.isOnscreen(), onscreen); return window; }
static void destroyWindow(final Window window, final boolean last) { if (null == window) { return; } final Screen screen = window.getScreen(); final Display display = screen.getDisplay(); window.destroy(); // System.err.println("************* Destroyed: "+window); if (last) { Assert.assertEquals(false, screen.isNativeValid()); Assert.assertEquals(false, display.isNativeValid()); } else { Assert.assertEquals(true, screen.isNativeValid()); Assert.assertEquals(true, display.isNativeValid()); } Assert.assertEquals(false, window.isNativeValid()); Assert.assertEquals(false, window.isVisible()); }
/** Applies all settings not related to OpenGL (screen resolution, screen size, etc...) */ private void applySettings() { _newtWindow.setUndecorated(_settings.isFullScreen()); _newtWindow.setFullscreen(_settings.isFullScreen()); // FIXME Ardor3D does not allow to change the resolution /** * uses the filtering relying on resolution with the size to fetch only the screen mode matching * with the current resolution */ if (_settings.isFullScreen()) { final Screen screen = _newtWindow.getScreen(); List<ScreenMode> screenModes = screen.getScreenModes(); // the resolution is provided by the user final Dimension dimension = new Dimension(_settings.getWidth(), _settings.getHeight()); screenModes = ScreenModeUtil.filterByResolution(screenModes, dimension); screenModes = ScreenModeUtil.getHighestAvailableBpp(screenModes); if (_settings.getFrequency() > 0) { screenModes = ScreenModeUtil.filterByRate(screenModes, _settings.getFrequency()); } else { screenModes = ScreenModeUtil.getHighestAvailableRate(screenModes); } screen.setCurrentScreenMode(screenModes.get(0)); } }
protected void initWindow() { window = GLWindow.create(screen, pgl.capabilities); if (displayDevice == null) { displayDevice = window.getMainMonitor(); } int displayNum = sketch.sketchDisplay(); if (displayNum > 0) { // if -1, use the default device if (displayNum <= monitors.size()) { displayDevice = monitors.get(displayNum - 1); } else { System.err.format( "Display %d does not exist, " + "using the default display instead.%n", displayNum); for (int i = 0; i < monitors.size(); i++) { System.err.format("Display %d is %s%n", i + 1, monitors.get(i)); } } } boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN; screenRect = spanDisplays ? new Rectangle(0, 0, screen.getWidth(), screen.getHeight()) : new Rectangle( 0, 0, displayDevice.getViewportInWindowUnits().getWidth(), displayDevice.getViewportInWindowUnits().getHeight()); // Set the displayWidth/Height variables inside PApplet, so that they're // usable and can even be returned by the sketchWidth()/Height() methods. sketch.displayWidth = screenRect.width; sketch.displayHeight = screenRect.height; sketchWidth = sketch.sketchWidth(); sketchHeight = sketch.sketchHeight(); boolean fullScreen = sketch.sketchFullScreen(); // Removing the section below because sometimes people want to do the // full screen size in a window, and it also breaks insideSettings(). // With 3.x, fullScreen() is so easy, that it's just better that way. // https://github.com/processing/processing/issues/3545 /* // Sketch has already requested to be the same as the screen's // width and height, so let's roll with full screen mode. if (screenRect.width == sketchWidth && screenRect.height == sketchHeight) { fullScreen = true; sketch.fullScreen(); } */ if (fullScreen || spanDisplays) { sketchWidth = screenRect.width; sketchHeight = screenRect.height; } float[] reqSurfacePixelScale; if (graphics.is2X()) { // Retina reqSurfacePixelScale = new float[] {ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE}; } else { // Non-retina reqSurfacePixelScale = new float[] {ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE}; } window.setSurfaceScale(reqSurfacePixelScale); window.setSize(sketchWidth, sketchHeight); setSize(sketchWidth, sketchHeight); sketchX = displayDevice.getViewportInWindowUnits().getX(); sketchY = displayDevice.getViewportInWindowUnits().getY(); if (fullScreen) { PApplet.hideMenuBar(); window.setTopLevelPosition(sketchX, sketchY); placedWindow = true; if (spanDisplays) { window.setFullscreen(monitors); } else { window.setFullscreen(true); } } }
protected void initScreen() { display = NewtFactory.createDisplay(null); display.addReference(); screen = NewtFactory.createScreen(display, 0); screen.addReference(); monitors = new ArrayList<MonitorDevice>(); GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] awtDevices = environment.getScreenDevices(); List<MonitorDevice> newtDevices = screen.getMonitorDevices(); // AWT and NEWT name devices in different ways, depending on the platform, // and also appear to order them in different ways. The following code // tries to address the differences. if (PApplet.platform == PConstants.LINUX) { for (GraphicsDevice device : awtDevices) { String did = device.getIDstring(); String[] parts = did.split("\\."); String id1 = ""; if (1 < parts.length) { id1 = parts[1].trim(); } MonitorDevice monitor = null; int id0 = newtDevices.size() > 0 ? newtDevices.get(0).getId() : 0; for (int i = 0; i < newtDevices.size(); i++) { MonitorDevice mon = newtDevices.get(i); String mid = String.valueOf(mon.getId() - id0); if (id1.equals(mid)) { monitor = mon; break; } } if (monitor != null) { monitors.add(monitor); } } } else { // All the other platforms... for (GraphicsDevice device : awtDevices) { String did = device.getIDstring(); String[] parts = did.split("Display"); String id1 = ""; if (1 < parts.length) { id1 = parts[1].trim(); } MonitorDevice monitor = null; for (int i = 0; i < newtDevices.size(); i++) { MonitorDevice mon = newtDevices.get(i); String mid = String.valueOf(mon.getId()); if (id1.equals(mid)) { monitor = mon; break; } } if (monitor == null) { // Didn't find a matching monitor, try using less stringent id check for (int i = 0; i < newtDevices.size(); i++) { MonitorDevice mon = newtDevices.get(i); String mid = String.valueOf(mon.getId()); if (-1 < did.indexOf(mid)) { monitor = mon; break; } } } if (monitor != null) { monitors.add(monitor); } } } }
protected void runTestGL(final GLCapabilities caps) throws AWTException, InterruptedException, InvocationTargetException { final JFrame frame = new JFrame("Swing GLJPanel"); frame.setLocation(xpos, ypos); Assert.assertNotNull(frame); final FPSAnimator animator = useAnimator ? new FPSAnimator(60) : null; final SnapshotGLEventListener snap = new SnapshotGLEventListener(); final GLJPanel glJPanel = newGLJPanel(frame, caps, animator, snap); if (null != animator) { animator.start(); Assert.assertEquals(true, animator.isAnimating()); } final Screen screen = NewtFactoryAWT.createScreen(glJPanel, true); screen.addReference(); // initial native creation - keep alive! System.err.println("GetPixelScale: AWT -> Screen: " + screen); final QuitAdapter quitAdapter = new QuitAdapter(); new AWTKeyAdapter(new TraceKeyAdapter(quitAdapter), glJPanel).addTo(glJPanel); new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter), glJPanel).addTo(frame); final JFrame[] frame2 = {null}; final GLJPanel[] glJPanel2 = {null}; final com.jogamp.newt.event.KeyListener kl = new com.jogamp.newt.event.KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.isAutoRepeat()) { return; } if (e.getKeySymbol() == KeyEvent.VK_P) { System.err.println(); { // Just for manual validation! final java.awt.Point los = glJPanel.getLocationOnScreen(); final RectangleImmutable r = new Rectangle(los.x, los.y, glJPanel.getWidth(), glJPanel.getHeight()); System.err.printf("GetPixelScale: Panel Bounds: %s window-units%n", r.toString()); System.err.printf( "GetPixelScale: Panel Resolution: %d x %d pixel-units%n", glJPanel.getSurfaceWidth(), glJPanel.getSurfaceHeight()); } final MonitorDevice monitor = NewtFactoryAWT.getMonitorDevice(screen, glJPanel); System.err.printf("GetPixelScale: %s%n", monitor.toString()); final float[] pixelPerMM; final boolean cached; if (e.isShiftDown()) { // SHIFT: query current mode! pixelPerMM = monitor.getPixelsPerMM(monitor.queryCurrentMode(), new float[2]); cached = false; } else { // Default: Use cached mode! pixelPerMM = monitor.getPixelsPerMM(new float[2]); cached = true; } System.err.println( " pixel/mm [" + pixelPerMM[0] + ", " + pixelPerMM[1] + "], cached-mode " + cached); System.err.println( " pixel/in [" + pixelPerMM[0] * 25.4f + ", " + pixelPerMM[1] * 25.4f + "], cached-mode " + cached); System.err.println(); } else if (e.getKeyChar() == 'x') { final float[] hadSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new float[2]); final float[] reqSurfacePixelScale; if (hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE) { reqSurfacePixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE }; } else { reqSurfacePixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE }; } System.err.println( "[set PixelScale pre]: had " + hadSurfacePixelScale[0] + "x" + hadSurfacePixelScale[1] + " -> req " + reqSurfacePixelScale[0] + "x" + reqSurfacePixelScale[1]); glJPanel.setSurfaceScale(reqSurfacePixelScale); final float[] valReqSurfacePixelScale = glJPanel.getRequestedSurfaceScale(new float[2]); final float[] hasSurfacePixelScale1 = glJPanel.getCurrentSurfaceScale(new float[2]); System.err.println( "[set PixelScale post]: " + hadSurfacePixelScale[0] + "x" + hadSurfacePixelScale[1] + " (had) -> " + reqSurfacePixelScale[0] + "x" + reqSurfacePixelScale[1] + " (req) -> " + valReqSurfacePixelScale[0] + "x" + valReqSurfacePixelScale[1] + " (val) -> " + hasSurfacePixelScale1[0] + "x" + hasSurfacePixelScale1[1] + " (has)"); setTitle(frame, glJPanel, caps); } else if (e.getKeyChar() == 'm') { final GLCapabilitiesImmutable capsPre = glJPanel.getChosenGLCapabilities(); final GLCapabilities capsNew = new GLCapabilities(capsPre.getGLProfile()); capsNew.copyFrom(capsPre); final boolean msaa; if (capsPre.getSampleBuffers()) { capsNew.setSampleBuffers(false); msaa = false; } else { capsNew.setSampleBuffers(true); capsNew.setNumSamples(4); msaa = true; } System.err.println("[set MSAA " + msaa + " Caps had]: " + capsPre); System.err.println("[set MSAA " + msaa + " Caps new]: " + capsNew); System.err.println("XXX-A1: " + animator.toString()); glJPanel.setRequestedGLCapabilities(capsNew); System.err.println("XXX-A2: " + animator.toString()); System.err.println("XXX: " + glJPanel.toString()); } else if (e.getKeyChar() == 'n') { System.err.println("XXX: frame2: " + frame2[0]); if (null != frame2[0]) { System.err.println("XXX: frame2.isShowing: " + frame2[0].isShowing()); } System.err.println("XXX: glJPanel2: " + glJPanel2[0]); if (null != frame2[0] && frame2[0].isShowing()) { destroy(frame2[0], glJPanel2[0]); frame2[0] = null; glJPanel2[0] = null; } else { frame2[0] = new JFrame("GLJPanel2"); frame2[0].setLocation(frame.getX() + frame.getWidth() + 64, frame.getY()); final FPSAnimator animator2 = useAnimator ? new FPSAnimator(60) : null; if (null != animator2) { animator2.start(); } final SnapshotGLEventListener snap2 = new SnapshotGLEventListener(); try { glJPanel2[0] = newGLJPanel(frame2[0], caps, animator2, snap2); } catch (final Exception e2) { e2.printStackTrace(); destroy(frame2[0], glJPanel2[0]); frame2[0] = null; glJPanel2[0] = null; } } } } }; new AWTKeyAdapter(kl, glJPanel).addTo(glJPanel); snap.setMakeSnapshot(); if (null != rwsize) { Thread.sleep(500); // 500ms delay setFrameSize(frame, true, rwsize); System.err.println( "window resize pos/siz: " + glJPanel.getX() + "/" + glJPanel.getY() + " " + glJPanel.getSurfaceWidth() + "x" + glJPanel.getSurfaceHeight()); } snap.setMakeSnapshot(); final long t0 = System.currentTimeMillis(); long t1 = t0; boolean triggerSnap = false; while (!quitAdapter.shouldQuit() && t1 - t0 < duration) { Thread.sleep(100); t1 = System.currentTimeMillis(); snap.getDisplayCount(); if (!triggerSnap && snap.getDisplayCount() > 1) { // Snapshot only after one frame has been rendered to suite FBO MSAA! snap.setMakeSnapshot(); triggerSnap = true; } } Assert.assertNotNull(frame); Assert.assertNotNull(glJPanel); if (useAnimator) { Assert.assertNotNull(animator); animator.stop(); Assert.assertEquals(false, animator.isAnimating()); } else { Assert.assertNull(animator); } screen.removeReference(); // final native destroy destroy(frame, glJPanel); if (null != frame2[0]) { destroy(frame2[0], glJPanel2[0]); } }