Login  Register

any one is using two screens?

Posted by cznlzq on Mar 12, 2014; 7:26pm
URL: https://forum.jogamp.org/any-one-is-using-two-screens-tp4031872.html

JOGL 2.1.2 + Java 7u51 in Windows 7.

Very simple code.

//======================================================================
package jogl.test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.jogamp.opengl.util.FPSAnimator;

public class testSimpleSceneJOGL implements GLEventListener {

    private double theta = 0;
    private double s = 1;
    private double c = 1;

    public static void main(String[] args) {

        final GLProfile glp = GLProfile.getDefault();
       
        final JFrame frame = new JFrame("AWT Window Test");
        frame.setSize(300, 300);
        JMenu file = new JMenu("File");
        file.setMnemonic('F');
        JMenuItem newItem = new JMenuItem("New");
        newItem.setMnemonic('N');
        file.add(newItem);
       
        //adding action listener to menu items
        newItem.addActionListener(
            new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent e)
                {
                    System.out.println("New is pressed");
                   
                    final GLCapabilities caps = new GLCapabilities(glp);
                    final GLCanvas canvas = new GLCanvas(caps);
                   
                    frame.add(canvas);
                   
                    canvas.addGLEventListener(new testSimpleSceneJOGL());

                    FPSAnimator animator = new FPSAnimator(canvas, 60);
                    animator.start();
                   
                    frame.revalidate();
                    frame.repaint();
                                       
                }
            });
       

        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
       
        JMenuBar bar = new JMenuBar();
        frame.setJMenuBar(bar);
        bar.add(file);
       
        frame.setLocation(2048, 100);        
        frame.setVisible(true);
    }

    @Override
    public void display(GLAutoDrawable drawable) {
        update();
        render(drawable);
    }

    @Override
    public void dispose(GLAutoDrawable drawable) {
    }

    @Override
    public void init(GLAutoDrawable drawable) {
    }

    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    }

    private void update() {
        theta += 0.01;
        s = Math.sin(theta);
        c = Math.cos(theta);
    }

    private void render(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);

        // draw a triangle filling the window
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glColor3f(1, 0, 0);
        gl.glVertex2d(-c, -c);
        gl.glColor3f(0, 1, 0);
        gl.glVertex2d(0, c);
        gl.glColor3f(0, 0, 1);
        gl.glVertex2d(s, -s);
        gl.glEnd();
    }
}

//=============================================================================

I'm using two screens.
In the code, I use frame.setLocation(2048, 100); to make the frame show up in my second screen.
And it gives me an error.
The frame.setLocation(100,100) to make the frame show up in my first screen works perfectly though.

Any one is using two screens and could you please give me some advices?

Thanks.

And here is the output message:

FPSAnimator P1:Thread[AWT-EventQueue-0-FPSAWTAnimator-Timer0,6,main]: Task[thread Thread[AWT-EventQueue-0-FPSAWTAnimator-Timer0,6,main], stopped false, paused false shouldRun true, shouldStop false -- started true, animating true, paused false, drawable 1, drawablesEmpty false]
Exception in thread "AWT-EventQueue-0-FPSAWTAnimator-Timer0" java.lang.RuntimeException: javax.media.opengl.GLException: Error making context 0x20000 current on Thread AWT-EventQueue-0, drawableWrite 0x7f0131bf, drawableRead 0x7f0131bf, werr: 0, WindowsWGLContext [Version 4.2 (Compat profile, arb, ES2 compat, FBO, hardware) - 4.2.11631 Compatibility Profile Context [GL 4.2.0, vendor 0.0.0 (n/a)], options 0x1403, this 0x11ffed1, handle 0x20000, isShared false, jogamp.opengl.gl4.GL4bcImpl@5a7b7,
         quirks: [NoDoubleBufferedBitmap, NeedCurrCtx4ARBCreateContext],
        Drawable: WindowsOnscreenWGLDrawable[Realized true,
        Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@145f6fb,
        Handle    0x7f0131bf,
        Surface   JAWT-Window[JAWT version: 0x10004, CA_LAYER: false, isLayeredSurface false, bounds [ 0 / 0  284 x 237 ], insets [ l 0, r 0 - t 0, b 0 - 0x0], shallUseOffscreenLayer false, isOffscreenLayerSurface false, attachedSurfaceLayer 0x0, windowHandle 0x230ec0, surfaceHandle 0x7f0131bf, bounds [ 0 / 0  284 x 237 ], insets [ l 0, r 0 - t 0, b 0 - 0x0], pos 0/0, size 284x237, visible true, lockedExt false,
        config AWTGraphicsConfiguration[AWTGraphicsScreen[AWTGraphicsDevice[type .awt, connection \Display0, unitID 0, awtDevice D3DGraphicsDevice[screen=0], handle 0x0], idx 0],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        sun.awt.Win32GraphicsConfig@165c64[dev=D3DGraphicsDevice[screen=0],pixfmt=2],
        encapsulated WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 2, ARB-Choosen true,
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]]]],
        awtComponent AWT-GLCanvas[Realized true,
        jogamp.opengl.windows.wgl.WindowsOnscreenWGLDrawable,
        Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@145f6fb,
        handle    0x7f0131bf,
        Drawable size 284x237,
        AWT pos 0/0, size 284x237,
        visible true, displayable true,
        AWTGraphicsConfiguration[AWTGraphicsScreen[AWTGraphicsDevice[type .awt, connection \Display0, unitID 0, awtDevice D3DGraphicsDevice[screen=0], handle 0x0], idx 0],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        sun.awt.Win32GraphicsConfig@165c64[dev=D3DGraphicsDevice[screen=0],pixfmt=2],
        encapsulated WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 2, ARB-Choosen true,
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]]]]],
        surfaceLock <5a14e3, 116623>[count 1, qsz 0, owner <AWT-EventQueue-0>]]]]
        at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
        at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
        at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
        at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
        at javax.media.opengl.Threading.invoke(Threading.java:191)
        at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:528)
        at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:75)
        at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:443)
        at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:170)
        at java.util.TimerThread.mainLoop(Unknown Source)
        at java.util.TimerThread.run(Unknown Source)
Caused by: javax.media.opengl.GLException: Error making context 0x20000 current on Thread AWT-EventQueue-0, drawableWrite 0x7f0131bf, drawableRead 0x7f0131bf, werr: 0, WindowsWGLContext [Version 4.2 (Compat profile, arb, ES2 compat, FBO, hardware) - 4.2.11631 Compatibility Profile Context [GL 4.2.0, vendor 0.0.0 (n/a)], options 0x1403, this 0x11ffed1, handle 0x20000, isShared false, jogamp.opengl.gl4.GL4bcImpl@5a7b7,
         quirks: [NoDoubleBufferedBitmap, NeedCurrCtx4ARBCreateContext],
        Drawable: WindowsOnscreenWGLDrawable[Realized true,
        Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@145f6fb,
        Handle    0x7f0131bf,
        Surface   JAWT-Window[JAWT version: 0x10004, CA_LAYER: false, isLayeredSurface false, bounds [ 0 / 0  284 x 237 ], insets [ l 0, r 0 - t 0, b 0 - 0x0], shallUseOffscreenLayer false, isOffscreenLayerSurface false, attachedSurfaceLayer 0x0, windowHandle 0x230ec0, surfaceHandle 0x7f0131bf, bounds [ 0 / 0  284 x 237 ], insets [ l 0, r 0 - t 0, b 0 - 0x0], pos 0/0, size 284x237, visible true, lockedExt false,
        config AWTGraphicsConfiguration[AWTGraphicsScreen[AWTGraphicsDevice[type .awt, connection \Display0, unitID 0, awtDevice D3DGraphicsDevice[screen=0], handle 0x0], idx 0],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        sun.awt.Win32GraphicsConfig@165c64[dev=D3DGraphicsDevice[screen=0],pixfmt=2],
        encapsulated WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 2, ARB-Choosen true,
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]]]],
        awtComponent AWT-GLCanvas[Realized true,
        jogamp.opengl.windows.wgl.WindowsOnscreenWGLDrawable,
        Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@145f6fb,
        handle    0x7f0131bf,
        Drawable size 284x237,
        AWT pos 0/0, size 284x237,
        visible true, displayable true,
        AWTGraphicsConfiguration[AWTGraphicsScreen[AWTGraphicsDevice[type .awt, connection \Display0, unitID 0, awtDevice D3DGraphicsDevice[screen=0], handle 0x0], idx 0],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        sun.awt.Win32GraphicsConfig@165c64[dev=D3DGraphicsDevice[screen=0],pixfmt=2],
        encapsulated WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 2, ARB-Choosen true,
        requested GLCaps[rgba 8/8/8/0, opaque, accum-rgba 0/0/0/0, dp/st/ms 16/0/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
        chosen    GLCaps[wgl vid 0x2 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/8/0, dbl, mono  , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]]]]],
        surfaceLock <5a14e3, 116623>[count 1, qsz 0, owner <AWT-EventQueue-0>]]]]
        at jogamp.opengl.windows.wgl.WindowsWGLContext.makeCurrentImpl(WindowsWGLContext.java:410)
        at jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:718)
        at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:562)
        at jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:519)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1089)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:978)
        at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1282)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$200(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)