JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
ManualScreenMode03aNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.newt.mm;
30
31import java.io.IOException;
32import com.jogamp.opengl.GLCapabilities;
33import com.jogamp.opengl.GLProfile;
34
35import com.jogamp.opengl.util.Animator;
36
37import com.jogamp.newt.Display;
38import com.jogamp.newt.MonitorDevice;
39import com.jogamp.newt.NewtFactory;
40import com.jogamp.newt.Screen;
41import com.jogamp.newt.MonitorMode;
42import com.jogamp.newt.opengl.GLWindow;
43import com.jogamp.newt.util.MonitorModeUtil;
44import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
45import com.jogamp.opengl.test.junit.util.UITestCase;
46import java.util.List;
47import com.jogamp.nativewindow.util.Dimension;
48
49/**
50 * Manual testing the ScreenImpl shutdown hook,
51 * which shall reset the ScreenMode to it's original state
52 * when the application exists (normal or ctrl-c).
53 */
54public class ManualScreenMode03aNEWT extends UITestCase {
55 static int waitTime = 7000; // 1 sec
56
57 static GLWindow createWindow(final Screen screen, final GLCapabilities caps, final int width, final int height, final boolean onscreen, final boolean undecorated) {
58 caps.setOnscreen(onscreen);
59
60 final GLWindow window = GLWindow.create(screen, caps);
61 window.setSize(width, height);
62 window.addGLEventListener(new GearsES2());
63 window.setVisible(true);
64 return window;
65 }
66
67 public void run() {
68 final int width = 640;
69 final int height = 480;
70 final GLProfile glp = GLProfile.getDefault();
71 final GLCapabilities caps = new GLCapabilities(glp);
72 final Display display = NewtFactory.createDisplay(null); // local display
73 final Screen screen = NewtFactory.createScreen(display, 0); // screen 0
74 final GLWindow window = createWindow(screen, caps, width, height, true /* onscreen */, false /* undecorated */);
75
76 final Animator animator = new Animator(window);
77 animator.start();
78
79 final MonitorDevice monitor = window.getMainMonitor();
80
81 final MonitorMode mmCurrent = monitor.queryCurrentMode();
82 final MonitorMode mmOrig = monitor.getOriginalMode();
83 System.err.println("[0] orig : "+mmOrig);
84 System.err.println("[0] current: "+mmCurrent);
85 List<MonitorMode> monitorModes = monitor.getSupportedModes();
86 if(null==monitorModes) {
87 // no support ..
88 System.err.println("Your platform has no ScreenMode change support, sorry");
89 return;
90 }
91 monitorModes = MonitorModeUtil.filterByFlags(monitorModes, 0); // no interlace, double-scan etc
92 monitorModes = MonitorModeUtil.filterByRotation(monitorModes, 0);
93 monitorModes = MonitorModeUtil.filterByResolution(monitorModes, new Dimension(801, 601));
94 monitorModes = MonitorModeUtil.filterByRate(monitorModes, mmOrig.getRefreshRate());
95 monitorModes = MonitorModeUtil.getHighestAvailableBpp(monitorModes);
96 final MonitorMode mm = monitorModes.get(0);
97 System.err.println("[0] set current: "+mm);
98 monitor.setCurrentMode(mm);
99
100 System.err.print("[0] post setting .. wait <");
101 try {
102 Thread.sleep(waitTime);
103 } catch (final InterruptedException e) {
104 }
105 System.err.println("done>");
106 System.exit(0);
107 }
108
109 public static void main(final String args[]) throws IOException {
111 t.run();
112 }
113}
void setOnscreen(final boolean onscreen)
Sets whether the surface shall be on- or offscreen.
Visual output device, i.e.
abstract MonitorMode queryCurrentMode()
Returns the current MonitorMode resulting from a native query.
abstract boolean setCurrentMode(MonitorMode mode)
Set the current com.jogamp.newt.MonitorMode.
final List< MonitorMode > getSupportedModes()
Returns a list of immutable MonitorModes supported by this monitor.
final MonitorMode getOriginalMode()
Returns the immutable original com.jogamp.newt.MonitorMode, as used at NEWT initialization.
Immutable MonitorMode Class, consisting of it's read only components:
final float getRefreshRate()
Returns the vertical refresh rate.
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final MonitorDevice getMainMonitor()
Returns the MonitorDevice with the highest viewport coverage of this window.
Definition: GLWindow.java:292
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Convenient com.jogamp.newt.MonitorMode utility methods, filters etc.
static List< MonitorMode > filterByFlags(final List< MonitorMode > monitorModes, final int flags)
static List< MonitorMode > filterByResolution(final List< MonitorMode > monitorModes, final DimensionImmutable resolution)
static List< MonitorMode > getHighestAvailableBpp(final List< MonitorMode > monitorModes)
static List< MonitorMode > filterByRotation(final List< MonitorMode > monitorModes, final int rotation)
static List< MonitorMode > filterByRate(final List< MonitorMode > monitorModes, final float refreshRate)
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static GLProfile getDefault(final AbstractGraphicsDevice device)
Returns a default GLProfile object, reflecting the best for the running platform.
Definition: GLProfile.java:739
Manual testing the ScreenImpl shutdown hook, which shall reset the ScreenMode to it's original state ...
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.