use of com.jogamp.newt.MonitorMode in project jmonkeyengine by jMonkeyEngine.
the class JoglNewtDisplay method applySettings.
protected void applySettings(AppSettings settings) {
active.set(true);
canvas.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyNotify(WindowEvent e) {
windowCloseRequest.set(true);
}
@Override
public void windowGainedFocus(WindowEvent e) {
active.set(true);
}
@Override
public void windowLostFocus(WindowEvent e) {
active.set(false);
}
});
canvas.setSize(settings.getWidth(), settings.getHeight());
canvas.setUndecorated(settings.isFullscreen());
canvas.setFullscreen(settings.isFullscreen());
/**
* uses the filtering relying on resolution with the size to fetch only
* the screen mode matching with the current resolution
*/
Screen screen = canvas.getScreen();
/**
* The creation of native resources is lazy in JogAmp, i.e they are
* created only when they are used for the first time. When the GLWindow
* is not yet visible, its screen might have been unused for now and
* then its native counterpart has not yet been created. That's why
* forcing the creation of this resource is necessary
*/
screen.addReference();
if (settings.isFullscreen()) {
List<MonitorMode> screenModes = canvas.getMainMonitor().getSupportedModes();
//the resolution is provided by the user
Dimension dimension = new Dimension(settings.getWidth(), settings.getHeight());
screenModes = MonitorModeUtil.filterByResolution(screenModes, dimension);
screenModes = MonitorModeUtil.getHighestAvailableBpp(screenModes);
if (settings.getFrequency() > 0) {
screenModes = MonitorModeUtil.filterByRate(screenModes, settings.getFrequency());
} else {
screenModes = MonitorModeUtil.getHighestAvailableRate(screenModes);
}
canvas.getMainMonitor().setCurrentMode(screenModes.get(0));
}
MonitorMode currentScreenMode = canvas.getMainMonitor().getCurrentMode();
logger.log(Level.FINE, "Selected display mode: {0}x{1}x{2} @{3}", new Object[] { currentScreenMode.getRotatedWidth(), currentScreenMode.getRotatedHeight(), currentScreenMode.getSurfaceSize().getBitsPerPixel(), currentScreenMode.getRefreshRate() });
}
use of com.jogamp.newt.MonitorMode in project narchy by automenta.
the class NEWTWin method setMode.
/**
* @param dim
* @param mode
* @param fullscreen
* @param driverName
* @return enum Base.rserr_t
*/
public int setMode(GLProfile glp, Dimension dim, int mode, boolean fullscreen, String driverName) {
final Dimension newDim = new Dimension();
VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display for profile " + glp + '\n');
if (null == screen) {
screen = NewtFactory.createScreen(NewtFactory.createDisplay(null), 0);
// trigger native creation
screen.addReference();
} else if (!screen.isNativeValid()) {
// trigger native creation
screen.addReference();
}
if (!VID.GetModeInfo(newDim, mode)) {
VID.Printf(Defines.PRINT_ALL, " invalid mode\n");
return Base.rserr_invalid_mode;
}
VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ", " + newDim.getWidth() + " x " + newDim.getHeight() + ", fs " + fullscreen + ", driver " + driverName + '\n');
// destroy the existing window, not screen
shutdownImpl(false);
if (null != window) {
throw new InternalError("XXX");
}
final GLCapabilities caps = new GLCapabilities(glp);
// default
CapabilitiesChooser chooser = null;
final cvar_t v = Cvar.Get("jogl_rgb565", "0", 0);
if (v.value != 0f) {
caps.setRedBits(5);
caps.setGreenBits(6);
caps.setBlueBits(5);
// don't trust native GL-TK chooser
chooser = new GenericGLCapabilitiesChooser();
}
window = GLWindow.create(screen, caps);
window.setAutoSwapBufferMode(false);
// we do handle QUIT on our own, no GLWindow.display() called.
window.setDefaultCloseOperation(WindowClosingProtocol.WindowClosingMode.DO_NOTHING_ON_CLOSE);
window.setCapabilitiesChooser(chooser);
window.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyNotify(WindowEvent e) {
// not applet and not already in shutdown ?
shouldQuit = null != window;
}
@Override
public void windowResized(WindowEvent e) {
propagateNewSize();
}
});
window.setTitle("Jake2 (" + driverName + "-newt-" + glp.getName().toLowerCase() + ')');
animCtrl = new GameAnimatorControl();
window.setAnimator(animCtrl);
final MonitorDevice mainMonitor = window.getMainMonitor();
if (oldDisplayMode == null) {
oldDisplayMode = mainMonitor.getCurrentMode();
}
// We need to feed the NEWT Window to the NEWTKBD
NEWTKBD.Init(window);
window.addWindowListener(NEWTKBD.listener);
window.addKeyListener(NEWTKBD.listener);
window.addMouseListener(NEWTKBD.listener);
window.setSize(newDim.getWidth(), newDim.getHeight());
// no display() invocation on other thread!
isAnimating = true;
// if( !fullscreen && Globals.appletMode ) {
// forceReleaseCtx = FORCE_RELEASE_CTX_VAL;
//
// // Notify the size listener about the change
// final SizeChangeListener listener = Globals.sizeChangeListener;
// if (listener != null) {
// listener.sizeChanged(newDim.getWidth(), newDim.getHeight());
// }
// window.addKeyListener( new ReparentKeyListener() );
//
// final NativeSurface NativeSurface = NewtFactory.createWindow(window);
// final java.applet.Applet applet = (java.applet.Applet) Globals.applet;
// final Runnable appletAddAction = () -> {
// applet.add(NativeSurface, java.awt.BorderLayout.CENTER);
// applet.validate();
// NativeSurface.setFocusable(true);
// NativeSurface.requestFocus();
// if( Platform.OSType.MACOS == Platform.getOSType() && NativeSurface.isOffscreenLayerSurfaceEnabled() ) {
// System.err.println("XXX Relayout");
// // force relayout
// final int cW = NativeSurface.getWidth();
// final int cH = NativeSurface.getHeight();
// NativeSurface.setSize(cW+1, cH+1);
// NativeSurface.setSize(cW, cH);
// }
// };
// if( java.awt.EventQueue.isDispatchThread() ) {
// System.err.println("XXX Adding on AWT EDT - same thread");
// appletAddAction.run();
// } else {
// System.err.println("XXX Adding on AWT EDT - off thread");
// try {
// java.awt.EventQueue.invokeAndWait(appletAddAction);
// } catch (Exception e) {
// throw new RuntimeException("NEWT Exception during NativeSurface on AWT-EDT", e);
// }
// }
// canvasObj = NativeSurface;
// int w=0;
// while ( w<10 && !window.isNativeValid()|| !window.isRealized() ) {
// w++;
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {}
// }
// System.err.println("XXX waited = "+w+" * 100 ms");
// } else {
forceReleaseCtx = false;
canvasObj = null;
if (fullscreen) {
MonitorMode mm = findDisplayMode(newDim);
final DimensionImmutable smDim = mm.getSurfaceSize().getResolution();
newDim.setWidth(smDim.getWidth());
newDim.setHeight(smDim.getHeight());
mainMonitor.setCurrentMode(mm);
VID.Printf(Defines.PRINT_ALL, "...MonitorMode " + mm + '\n');
window.setFullscreen(true);
}
window.setVisible(true);
window.requestFocus();
if (!window.isNativeValid() || !window.isRealized()) {
throw new RuntimeException("NEWT window didn't not realize: " + window);
}
// force GL creation
window.display();
final GLContext ctx = window.getContext();
if (!ctx.isCreated()) {
System.err.println("Warning: GL context not created: " + ctx);
}
if (ctx.isCurrent()) {
throw new RuntimeException("NEWT GL context still current: " + ctx);
}
VID.Printf(Defines.PRINT_ALL, "...reques GLCaps " + window.getRequestedCapabilities() + '\n');
VID.Printf(Defines.PRINT_ALL, "...chosen GLCaps " + window.getChosenGLCapabilities() + '\n');
VID.Printf(Defines.PRINT_ALL, "...size " + window.getWidth() + " x " + window.getHeight() + '\n');
// propagateNewSize("init");
activateGLContext(true);
return Base.rserr_ok;
}
use of com.jogamp.newt.MonitorMode in project narchy by automenta.
the class VID method initModeList.
static void initModeList() {
final List<MonitorMode> modes = re.getModeList();
final ArrayList<String> fs_resolutions_list = new ArrayList<>();
final ArrayList<vidmode_t> fs_modes_list = new ArrayList<>();
final HashSet<DimensionImmutable> resSet = new HashSet<>();
for (int i = 0; i < modes.size(); i++) {
// reverse order: low -> high res.
final MonitorMode mm = modes.get(modes.size() - 1 - i);
final SurfaceSize ss = mm.getSurfaceSize();
final DimensionImmutable m = ss.getResolution();
if (resSet.add(m)) {
final StringBuilder sb = new StringBuilder();
sb.append('[');
sb.append(m.getWidth());
sb.append(' ');
sb.append(m.getHeight());
while (sb.length() < 10) sb.append(' ');
sb.append(']');
fs_resolutions_list.add(sb.toString());
sb.setLength(0);
sb.append("Mode ");
sb.append(i);
sb.append(':');
sb.append(m.getWidth());
sb.append('x');
sb.append(m.getHeight());
fs_modes_list.add(new vidmode_t(sb.toString(), m.getWidth(), m.getHeight(), i));
}
}
fs_resolutions = new String[fs_resolutions_list.size()];
fs_modes = new vidmode_t[fs_modes_list.size()];
fs_resolutions_list.toArray(fs_resolutions);
fs_modes_list.toArray(fs_modes);
}
Aggregations