use of com.jogamp.newt.event.WindowAdapter 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.event.WindowAdapter in project narchy by automenta.
the class PreviewMain method main.
public static void main(String... argv) throws Exception {
// Frame frame = new Frame("Vorschau der Szene");
/*
GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
caps.setStencilBits(1);
GLJPanel canvas = new GLJPanel(caps);
*/
// http://jogamp.org/git/?p=jogl-demos.git;a=blob;f=src/demos/es2/RawGL2ES2demo.java;hb=HEAD
GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
// We may at this point tweak the caps and request a translucent drawable
caps.setBackgroundOpaque(false);
caps.setStencilBits(1);
caps.setHardwareAccelerated(true);
GLWindow glWindow = GLWindow.create(caps);
// Registieren des OpenGL-Objekts:
glWindow.addGLEventListener(new OpenGLBox());
// Animator erzeugen:
final Animator animator = new Animator();
animator.add(glWindow);
glWindow.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyNotify(com.jogamp.newt.event.WindowEvent windowEvent) {
animator.stop();
System.exit(0);
}
@Override
public void windowGainedFocus(com.jogamp.newt.event.WindowEvent windowEvent) {
animator.start();
}
@Override
public void windowLostFocus(com.jogamp.newt.event.WindowEvent windowEvent) {
animator.stop();
}
});
// Fenster anzeigen:
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
glWindow.setSize(d.width, d.height);
// glWindow.setExtendedState(Frame.MAXIMIZED_BOTH);
glWindow.setVisible(true);
}
use of com.jogamp.newt.event.WindowAdapter 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.event.WindowAdapter in project jmonkeyengine by jMonkeyEngine.
the class NewtMouseInput method setInputSource.
public void setInputSource(GLWindow comp) {
if (component != null) {
component.removeMouseListener(this);
eventQueue.clear();
wheelPos = 0;
isRecentering = false;
eventsSinceRecenter = 0;
lastEventX = 0;
lastEventY = 0;
lastEventWheel = 0;
location = new Point();
centerLocation = new Point();
lastKnownLocation = new Point();
lockPosition = new Point();
}
component = comp;
component.addMouseListener(this);
component.addWindowListener(new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent e) {
setCursorVisible(visible);
}
@Override
public void windowLostFocus(WindowEvent e) {
//without those lines,
//on Linux (OpenBox) the mouse is not restored if invisible (eg via Alt-Tab)
component.setPointerVisible(true);
component.confinePointer(false);
}
});
}
use of com.jogamp.newt.event.WindowAdapter in project narchy by automenta.
the class OSMTest method main.
public static void main(String[] args) {
// https://wiki.openstreetmap.org/wiki/API_v0.6
// http://api.openstreetmap.org/api/0.6/changeset/#id/comment
// /api/0.6/map?bbox=min_lon,min_lat,max_lon,max_lat (W,S,E,N)
IRL i = new IRL(User.the());
i.load(-80.65, 28.58, -80.60, 28.63);
SpaceGraphPhys3D sg = new SpaceGraphPhys3D(new OsmSpace(i.osm));
sg.show(800, 800);
sg.addWindowListener(new WindowAdapter() {
@Override
public void windowDestroyed(WindowEvent e) {
super.windowDestroyed(e);
System.exit(0);
}
});
sg.add(new SubOrtho(WidgetTest.widgetDemo()).posWindow(0, 0, 0.3f, 1f));
}
Aggregations