Login  Register

Re: any one is using two screens?

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

Hi gouessej,

JOGL is updated so fast, I didn't notice that it's already 2.1.5.

Anyway, following your instructions,
I downloaded the 2.1.5 from http://jogamp.org/deployment/v2.1.5/archive/
and I found some online NEWT codes in which I setPosition to my second monitor.

Codes:

JOGL2NewtDemo.java

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

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;

import com.jogamp.newt.event.WindowListener;
import com.jogamp.newt.event.WindowUpdateEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.util.FPSAnimator;

public class JOGL2NewtDemo
{
    private static String TITLE = "JOGL 2 with NEWT";  // window's title
    private static final int WINDOW_WIDTH = 640;  // width of the drawable
    private static final int WINDOW_HEIGHT = 480; // height of the drawable
    private static final int FPS = 60; // animator's target frames per second

    static {
        GLProfile.initSingleton();  // The method allows JOGL to prepare some Linux-specific locking optimizations
    }

    /**
     * The entry main() method.
     */
    public static void main(String[] args) {
        // Get the default OpenGL profile, reflecting the best for your running platform
        GLProfile glp = GLProfile.getDefault();
        // Specifies a set of OpenGL capabilities, based on your profile.
        GLCapabilities caps = new GLCapabilities(glp);
        // Create the OpenGL rendering canvas
        GLWindow window = GLWindow.create(caps);

        // Create a animator that drives canvas' display() at the specified FPS.
        final FPSAnimator animator = new FPSAnimator(window, FPS, true);

        window.addWindowListener(new WindowListener()
        {

            @Override
            public void windowDestroyNotify(
                com.jogamp.newt.event.WindowEvent arg0)
            {
                // Use a dedicate thread to run the stop() to ensure that the
                // animator stops before program exits.
                new Thread() {
                    @Override
                    public void run() {
                        if (animator.isStarted())
                            animator.stop();    // stop the animator loop
                        System.exit(0);
                    }
                }.start();
            }

            @Override
            public void windowDestroyed(com.jogamp.newt.event.WindowEvent arg0)
            {
                // TODO Auto-generated method stub
               
            }

            @Override
            public void windowGainedFocus(com.jogamp.newt.event.WindowEvent arg0)
            {
                // TODO Auto-generated method stub
               
            }

            @Override
            public void windowLostFocus(com.jogamp.newt.event.WindowEvent arg0)
            {
                // TODO Auto-generated method stub
               
            }

            @Override
            public void windowMoved(com.jogamp.newt.event.WindowEvent arg0)
            {
                // TODO Auto-generated method stub
               
            }

            @Override
            public void windowRepaint(WindowUpdateEvent arg0)
            {
                // TODO Auto-generated method stub
               
            }

            @Override
            public void windowResized(com.jogamp.newt.event.WindowEvent arg0)
            {
                // TODO Auto-generated method stub
               
            }
           
        });

        window.addGLEventListener(new JOGL2Renderer());
        window.setPosition(2048, 100);
        window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        window.setTitle(TITLE);
        window.setVisible(true);
        animator.start();  // start the animator loop
    }
}
//===============================================================


JOGL2Renderer.java

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

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;

public class JOGL2Renderer implements GLEventListener {
    private double theta = 0.0f;  // rotational angle

    /**
     * Called back by the drawable to render OpenGL graphics
     */
    @Override
    public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();   // get the OpenGL graphics context

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);    // clear background
        gl.glLoadIdentity();                   // reset the model-view matrix    

          // Rendering code - draw a triangle
        float sine = (float)Math.sin(theta);
        float cosine = (float)Math.cos(theta);
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glColor3f(1, 0, 0);
        gl.glVertex2d(-cosine, -cosine);
        gl.glColor3f(0, 1, 0);
        gl.glVertex2d(0, cosine);
        gl.glColor3f(0, 0, 1);
        gl.glVertex2d(sine, -sine);
        gl.glEnd();

        update();
    }

    /**
     * Update the rotation angle after each frame refresh
     */
    private void update() {
        theta += 0.01;
    }

    @Override
    public void dispose(GLAutoDrawable arg0)
    {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void init(GLAutoDrawable arg0)
    {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void reshape(
        GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4)
    {
        // TODO Auto-generated method stub
       
    }

    /*... Other methods leave blank ...*/
}
//=====================================================================

result:

When I window.setPosition(100, 100) to first monitor, everything works perfectly.
However, when I window.setPosition(2048, 100) to second monitor, error message:

FPSAnimator P1:Thread[main-FPSAWTAnimator-Timer0,5,main]: Task[thread Thread[main-FPSAWTAnimator-Timer0,5,main], stopped false, paused false shouldRun true, shouldStop false -- started true, animating true, paused false, drawable 1, drawablesEmpty false]
Exception in thread "main-FPSAWTAnimator-Timer0" javax.media.opengl.GLException: Error making context 0x20000 current on Thread main-FPSAWTAnimator-Timer0, drawableWrite 0xffffffffe8011842, drawableRead 0xffffffffe8011842, 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 0x3bf486, handle 0x20000, isShared false, jogamp.opengl.gl4.GL4bcImpl@afd218,
         quirks: [NoDoubleBufferedBitmap, NeedCurrCtx4ARBCreateContext],
        Drawable: WindowsOnscreenWGLDrawable[Realized true,
        Factory   jogamp.opengl.windows.wgl.WindowsWGLDrawableFactory@10a280f,
        Handle    0xffffffffe8011842,
        Surface   jogamp.newt.driver.windows.WindowDriver[Config 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[.]]]
, NEWT-Screen[.windows_nil-1-s0, idx 0, refCount 1, vsize [ 0 / 0  3200 x 1080 ], DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], NEWT-Display[.windows_nil-1, excl false, refCount 1, hasEDT true, edtRunning true, WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]]], monitors: [Monitor[Id 0x0, 677 x 381 mm, viewport [ 0 / 0  1920 x 1080 ], orig [Id 0x0, [ 1920 x 1080 x 32 bpp ] @ 60.0 Hz, flags [], 0 degr], curr [Id 0x0, [ 1920 x 1080 x 32 bpp ] @ 60.0 Hz, flags [], 0 degr], modeChanged false, modeCount 368], Monitor[Id 0x1, 452 x 361 mm, viewport [ 1920 / 0  1280 x 1024 ], orig [Id 0x0, [ 1280 x 1024 x 32 bpp ] @ 60.0 Hz, flags [], 0 degr], curr [Id 0x0, [ 1280 x 1024 x 32 bpp ] @ 60.0 Hz, flags [], 0 degr], modeChanged false, modeCount 248]]]
, ParentWindow null
, ParentWindowHandle 0x0 (false)
, WindowHandle 0xc1836
, SurfaceHandle 0xffffffffe8011842 (lockedExt window false, surface false)
, Pos 2048/100 (auto false), size 640x480
, Visible true, focus false
, Undecorated false (false)
, AlwaysOnTop false, Fullscreen false
, WrappedSurface null
, ChildWindows 0, SurfaceUpdatedListeners num 0 [], WindowListeners num 2 [com.jogamp.newt.opengl.GLWindow$2@1cc0af6, jogl.test.JOGL2NewtDemo$1@e3cd9c, ], MouseListeners num 0 [], PointerGestures default true, custom 0 [], KeyListeners num 0 [], windowLock <1cfe433, 18f11d3>[count 2, qsz 0, owner <main-FPSAWTAnimator-Timer0>], surfaceLockCount 1]]]
        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 com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:600)
        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)
============================================================================