Search in sources :

Example 1 with Screen

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() });
}
Also used : MonitorMode(com.jogamp.newt.MonitorMode) Screen(com.jogamp.newt.Screen) WindowEvent(com.jogamp.newt.event.WindowEvent) WindowAdapter(com.jogamp.newt.event.WindowAdapter) Dimension(com.jogamp.nativewindow.util.Dimension)

Example 2 with Screen

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();
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Screen(com.jogamp.newt.Screen) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) Display(com.jogamp.newt.Display) MonitorDevice(com.jogamp.newt.MonitorDevice)

Aggregations

Screen (com.jogamp.newt.Screen)2 Dimension (com.jogamp.nativewindow.util.Dimension)1 Display (com.jogamp.newt.Display)1 MonitorDevice (com.jogamp.newt.MonitorDevice)1 MonitorMode (com.jogamp.newt.MonitorMode)1 WindowAdapter (com.jogamp.newt.event.WindowAdapter)1 WindowEvent (com.jogamp.newt.event.WindowEvent)1 GraphicsDevice (java.awt.GraphicsDevice)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 Point (java.awt.Point)1