use of com.jogamp.newt.Screen 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.Screen in project processing by processing.
the class PSurfaceJOGL method initDisplay.
protected void initDisplay() {
Display tmpDisplay = NewtFactory.createDisplay(null);
tmpDisplay.addReference();
Screen tmpScreen = NewtFactory.createScreen(tmpDisplay, 0);
tmpScreen.addReference();
monitors = new ArrayList<MonitorDevice>();
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] awtDevices = environment.getScreenDevices();
List<MonitorDevice> newtDevices = tmpScreen.getMonitorDevices();
// 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 if (PApplet.platform == PConstants.WINDOWS) {
// NEWT display id is == (adapterId << 8 | monitorId),
// should be in the same order as AWT
monitors.addAll(newtDevices);
} else {
// MAC OSX and others
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);
}
}
}
displayDevice = null;
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));
}
}
} else if (0 < monitors.size()) {
displayDevice = monitors.get(0);
}
if (displayDevice != null) {
screen = displayDevice.getScreen();
display = screen.getDisplay();
} else {
screen = tmpScreen;
display = tmpDisplay;
displayDevice = screen.getPrimaryMonitor();
}
}
Aggregations