Mac Canvas3D location bug

classic Classic list List threaded Threaded
88 messages Options
12345
Reply | Threaded
Open this post in threaded view
|

Mac Canvas3D location bug

jimthev
I found this wonderful project and got our programs working except that the canvas location is broken on the MacOSX version.  This is apparently a known bug but thought to be related to JDK7.

I'm running the Apple 1.6 Java on a 10.6 OSX and having the same problems.  Running a simple Canvas3D placed off the origin in a null layout applet shows the problem (take any basic Java3D Applet example, set the layout manager to null and do a setBounds on the canvas with nonzero x and y values).  The Canvas will show up at around 0, 500 or so rather than at the specified bounds location.  The height/width seem correct.

I'm using Java3D from http://jogamp.org/deployment/java3d/1.6.0-pre8/
and Jogl from https://jogamp.org/deployment/jogamp-current/archive/

So my question is: will using Oracle's Java 7u40 on 10.8 fix this problem?

When I tried to debug this issue it seemed like I needed a debug build of
https://github.com/sgothel/jogl/blob/master/src/nativewindow/native/macosx/OSXmisc.m
where VERBOSE is set to 1.  I can't build the native OSX libraries, but if someone has a debug build of them, I'll test what values are getting sent into the native window side.
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

gouessej
Administrator
Hi

Using OpenJDK or Oracle Java 1.7 fixes some bugs but there is at least a small regression. Everything "should" be ok when Java 1.8 is out.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

hharrison
In reply to this post by jimthev
I was trying to debug this a bit with somebody this weekend, I've pushed a debug build of java3d that has some fairly
verbose Canvas3D debugging turned on, you can find it here:

http://jogamp.org/deployment/java3d/dbg/

Get the -cvcdbg version (Canvas View Cache).  It appears that the issue is not solved with u40, but it does appear that
the values being _calculated_ for the Canvas3d are correct, but it would be great if you could confirm that.

You'll get debug spew on stderr, look for lines giving the position before/after a move or resize, the pos values quoted will
be x-y screen coordinates for the top left corner of the Canvas3d, in screen coordinates.  Please confirm that the values
coming out look correct for you, if they do, then either Java3d is somehow passing it to jogl incorrectly, or jogl is doing something odd.

Julien/Sven, any ideas on how to dump out the jogl side of things to correlate the two?

Harvey
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

gouessej
Administrator
hharrison wrote
Julien/Sven, any ideas on how to dump out the jogl side of things to correlate the two?
-Dnewt.debug=all -Dnativewindow.debug=all -Djogl.debug=all ???
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

jimthev
This post was updated on .
In reply to this post by hharrison
hharrison wrote
Please confirm that the values
coming out look correct for you, if they do, then either Java3d is somehow passing it to jogl incorrectly, or jogl is doing something odd.
The debug values of "Canvas Pos =" are correct.  They are the correct screen coordinates from the upper left of the screen where the Canvas3D should be located but isn't.

Upon further research, when you set the Canvas3D bounds to x,y,w,h in an applet with a null layout manager.
x is ignored, the x value used is always the left side of the applet.
y is ignored
w is used and is correct
h is correctly used as the height but it is also used as the y coordinate but the zero is on the bottom rather than the top and seems to be shifted down by 22 pixels on a 1280 x 800 display.

So the actual bounds in screen coordinates turns out to be something like: (applet bounds.x, 800 - h + 22, w, h) [EDIT: the coordinate system is from the lower left of the applet area.  My area extended about 22 pixels below the bottom of the screen during testing]
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

jimthev
After finally being able to compile jogl on OSX 10.6 here is where I'm at:

The location that is being drawn on the screen is being set in:

https://github.com/sgothel/jogl/blob/master/src/nativewindow/native/macosx/OSXmisc.m

in the static void FixCALayerLayout0 function.

There the coordinate system is from the lower left of the applet area so:

            lRect.origin.x = 0;
            lRect.origin.y = 0;
            lRect.size.width = width;
            lRect.size.height = height;
            [rootLayer setFrame: lRect];

Sets the frame to the bottom left of the entire applet area and shrinks it so that it is the width of the Canvas3D.  If I override the origin x and y values then the frame moves as you'd think with 0,0 being lower left of the applet area

I'm going to try to trace it backwards to see what values should be set where and maybe other values need to be passed or calculated, but if somebody knows what needs to be done and can jump to the answer, that'd be great.

Another thing to note:  
When initialized,  
    CGRect lRect = [rootLayer frame];
is the entire size of the applet area with x,y = 0;
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

jimthev
As a follow up, this isn't a Java3D problem.

A trivial GLCanvas shows up in the wrong spot.
While a trivial GLJPanel shows up in the correct spot.
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

hharrison
Sven just pushed out some fixes for this, can you please try with commit 4b5435c68c3f12d62dadb395957362eceacfb25c
which has been pushed out to the JOGL repos.

Harvey
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Sven Gothel
Administrator
On 09/24/2013 11:44 PM, hharrison [via jogamp] wrote:
> Sven just pushed out some fixes for this, can you please try with commit
> 4b5435c68c3f12d62dadb395957362eceacfb25c
> which has been pushed out to the JOGL repos.
>

.. as covered by:
  - maven 2.1.0-rc-20130925 (our repo)
  - http://jogamp.org/deployment/archive/master/gluegen_718-joal_477-jogl_1081-jocl_843/
  - http://jogamp.org/deployment/archive/master/gluegen_718-joal_477-jogl_1081-jocl_843-signed/

(the media-cube bug is fixed and pushed to git as exposed in above builds)

> Harvey

~Sven




signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Manu
Sorry Sven, your changes didn't fix the issue. The Canvas3D instance is still glued at the bottom corner of the frame in Sweet Home 3D.
Do you want me to prepare a DMG file of the application where you'll be able to easily replace the JOGL Jar files for your tests?

Many thanks for your efforts and good luck to find the last main bug that will put back Java 3D on the good path under Mac OS X.
Emmanuel Puybaret
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Sven Gothel
Administrator
On 09/25/2013 09:20 AM, Manu [via jogamp] wrote:
> Sorry Sven, your changes didn't fix the issue. The Canvas3D instance is still
> glued at the bottom corner of the frame in Sweet Home 3D.
> Do you want me to prepare a DMG file of the application where you'll be able
> to easily replace the JOGL Jar files for your tests?

Yes, that would help me alot!

~Sven

>
> Many thanks for your efforts and good luck to find the last main bug that will
> put back Java 3D on the good path under Mac OS X.
> Emmanuel Puybaret
>


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Sven Gothel
Administrator
In reply to this post by Manu
On 09/25/2013 08:14 PM, Sven Gothel wrote:
> On 09/25/2013 09:20 AM, Manu [via jogamp] wrote:
>> Sorry Sven, your changes didn't fix the issue. The Canvas3D instance is still
>> glued at the bottom corner of the frame in Sweet Home 3D.
>> Do you want me to prepare a DMG file of the application where you'll be able
>> to easily replace the JOGL Jar files for your tests?
>
> Yes, that would help me alot!
>

Of course, if you could extend the unit test (as well)
to provoke same 'misplacement' .. it would be even better!

This would allow to check for regressions etc.

> ~Sven
>
>>


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Manu
It's still more simple to generate a unit test for me, and it will be easier for you to test your changes.
So, here's a simple test showing a color cube in a canvas 3D laid out with split panes:
import java.awt.GraphicsEnvironment;
import javax.media.j3d.*;
import javax.swing.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Canvas3DPositionTest {
  public static void main(String [] args) {
    // Create a simple scene with a rotated color cube
    BranchGroup root = new BranchGroup();
    Transform3D rotation = new Transform3D();
    rotation.rotX(Math.PI / 9);
    TransformGroup rotationGroup = new TransformGroup(rotation);
    root.addChild(rotationGroup);
    rotationGroup.addChild(new ColorCube(0.5f));
    
    // Add scene to a new canvas 3D
    GraphicsConfigTemplate3D gc = new GraphicsConfigTemplate3D();
    Canvas3D canvas = new Canvas3D(GraphicsEnvironment.getLocalGraphicsEnvironment().
        getDefaultScreenDevice().getBestConfiguration(gc));
    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(root);

    // Build a GUI where the canvas 3D is supposed to be located at the top right 
    // of the frame and can be resized with split panes dividers
    JFrame frame = new JFrame("Canvas3DPositionTest");
    JSplitPane horizontalSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 
        true, new JScrollPane(), canvas);
    horizontalSplitPane.setResizeWeight(0.5);
    JSplitPane verticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, 
        true, horizontalSplitPane, new JScrollPane());    
    verticalSplitPane.setResizeWeight(0.5);
    frame.add(verticalSplitPane);
    frame.setSize(400, 400);
    frame.setVisible(true);
  }
}

Hope this will help.
Emmanuel Puybaret
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

jimthev
In reply to this post by hharrison
I still get the error for applets with this change.  For testing I use this class:
package test;

import java.applet.Applet;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JoglCanvasTest extends Applet implements GLEventListener {

  public JoglCanvasTest() {
  }

  public static JFrame frame;
  public static JPanel appletHolder;
  public static boolean isApplet = true;

  static public void main(String args[]) {
    Applet myApplet = null;
    isApplet = false;

    myApplet = new JoglCanvasTest();
    appletStarter(myApplet, "JoglCanvasTest", 800, 600);
  }

  static public void appletStarter(final Applet des, String frameName, int width, int height) {
    appletHolder = new JPanel();
    if (frame != null) {
      frame.dispose();
      frame = null;
    }
    frame = new JFrame(frameName);
    frame.setVisible(false);
    frame.getContentPane().add(appletHolder);

    appletHolder.setLayout(null);
    des.setBounds(0, 0, width, height);
    appletHolder.add(des);

    frame.setVisible(true);
    int frameBorderSize = appletHolder.getLocationOnScreen().x - frame.getLocationOnScreen().x;
    int titleBarHeight = appletHolder.getLocationOnScreen().y - frame.getLocationOnScreen().y;
    int frameWidth = width + 2 * frameBorderSize;
    int frameHeight = height + titleBarHeight + frameBorderSize;
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(frameWidth, frameHeight);
    frame.setVisible(true);
    des.init();
    frame.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
  }

  public void init() {
    initOpenGLAWT();
  }

  public void initOpenGLAWT() {
    setBackground(Color.gray);
    setLayout(null);

    GLProfile glp = GLProfile.getDefault();
    GLCapabilities caps = new GLCapabilities(glp);
    GLCanvas canvas = new GLCanvas((GLCapabilitiesImmutable) caps);
    canvas.setBounds(50, 50, 200, 450);
    canvas.addGLEventListener(this);
    add(canvas);
  }

  public void init(GLAutoDrawable gLAutoDrawable) {
    GL gl = gLAutoDrawable.getGL();
    gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gLAutoDrawable.swapBuffers();
  }

  public void dispose(GLAutoDrawable glad) {
  }

  public void display(GLAutoDrawable glad) {
  }

  public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
  }

}
in the jar "JoglCanvasTest.jar".  Along with this html ("applet.html"):
<html>
<body>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      width="800" height="600">
   <PARAM NAME = CODEBASE VALUE = ".">
   <param name="code" value="test.JoglCanvasTest">
   <param name="archive" value="lib/gluegen-rt.jar,
                                lib/jogl-all.jar,
                                JoglCanvasTest.jar">
   <comment>
     <embed code="test.JoglCanvasTest"
          CODEBASE = "."
          width="800" height="600"
          type="application/x-java-applet;version=1.6"
          archive="lib/gluegen-rt.jar,
                   lib/jogl-all.jar,
                   JoglCanvasTest.jar"
     </embed>
   </comment>
</object>
</body>
</html>
I put those two file in the same directory.  I have a subdirectory there called 'lib' that there that contains gluegen-rt.jar, jogl-all.jar and the appropriate natives jars.  You can either load the html page and run it in a browser or run the class as an application directly ("java -cp JoglCanvasTest.jar:lib\gluegen-rt.jar:lib\gluegen-rt-natives-macosx-universal.jar:lib\jogl-all.jar:lib\jogl-all-natives-macosx-universal.jar test.JoglCanvasTest").

When I open the html page in a browser on OSX 10.6 using Apple's Java 1.6, the box is black and in the lower left (this is the error case).
When I run the applet directly as an application under OSX 10.6 using Apple's Java 1.6 the box is red and in the correct location.

Under Windows the box is always in the correct location and is black as an applet and red as an application.
The color difference is because I'm intentionally not doing anything with the 'reshape'.
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Sven Gothel
Administrator
On 09/26/2013 06:00 PM, jimthev [via jogamp] wrote:

> I still get the error for applets with this change.  For testing I use this
> class:
>
> package test;
>
> import java.applet.Applet;
> import java.awt.Color;
> import java.awt.event.WindowAdapter;
> import java.awt.event.WindowEvent;
> import javax.media.opengl.GL;
> import javax.media.opengl.GLAutoDrawable;
> import javax.media.opengl.GLCapabilities;
> import javax.media.opengl.GLCapabilitiesImmutable;
> import javax.media.opengl.GLEventListener;
> import javax.media.opengl.GLProfile;
> import javax.media.opengl.awt.GLCanvas;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
>
> public class JoglCanvasTest extends Applet implements GLEventListener {
>
>   public JoglCanvasTest() {
>   }
>
>   public static JFrame frame;
>   public static JPanel appletHolder;
>   public static boolean isApplet = true;
>
>   static public void main(String args[]) {
>     Applet myApplet = null;
>     isApplet = false;
>
>     myApplet = new JoglCanvasTest();
>     appletStarter(myApplet, "JoglCanvasTest", 800, 600);
>   }
>
>   static public void appletStarter(final Applet des, String frameName, int width, int height) {
>     appletHolder = new JPanel();
>     if (frame != null) {
>       frame.dispose();
>       frame = null;
>     }
>     frame = new JFrame(frameName);
>     frame.setVisible(false);
>     frame.getContentPane().add(appletHolder);
>
>     appletHolder.setLayout(null);
>     des.setBounds(0, 0, width, height);
>     appletHolder.add(des);
>
>     frame.setVisible(true);
>     int frameBorderSize = appletHolder.getLocationOnScreen().x - frame.getLocationOnScreen().x;
>     int titleBarHeight = appletHolder.getLocationOnScreen().y - frame.getLocationOnScreen().y;
>     int frameWidth = width + 2 * frameBorderSize;
>     int frameHeight = height + titleBarHeight + frameBorderSize;
>     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>     frame.setSize(frameWidth, frameHeight);
>     frame.setVisible(true);
>     des.init();
>     frame.addWindowListener(new WindowAdapter() {
>       public void windowClosing(WindowEvent e) {
>         System.exit(0);
>       }
>     });
>   }
>
>   public void init() {
>     initOpenGLAWT();
>   }
>
>   public void initOpenGLAWT() {
>     setBackground(Color.gray);
>     setLayout(null);
>
>     GLProfile glp = GLProfile.getDefault();
>     GLCapabilities caps = new GLCapabilities(glp);
>     GLCanvas canvas = new GLCanvas((GLCapabilitiesImmutable) caps);
>     canvas.setBounds(50, 50, 200, 450);
>     canvas.addGLEventListener(this);
>     add(canvas);
>   }
>
>   public void init(GLAutoDrawable gLAutoDrawable) {
>     GL gl = gLAutoDrawable.getGL();
>     gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
>     gl.glClear(GL.GL_COLOR_BUFFER_BIT);
>     gLAutoDrawable.swapBuffers();
>   }
>
>   public void dispose(GLAutoDrawable glad) {
>   }
>
>   public void display(GLAutoDrawable glad) {
>   }
>
>   public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
>   }
>
> }
>
> in the jar "JoglCanvasTest.jar".  Along with this html ("applet.html"):
>
> <html>
> <body>
> <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
>       width="800" height="600">
>    <PARAM NAME = CODEBASE VALUE = ".">
>    <param name="code" value="test.JoglCanvasTest">
>    <param name="archive" value="lib/gluegen-rt.jar,
>                                 lib/jogl-all.jar,
>                                 JoglCanvasTest.jar">
>    <comment>
>      <embed code="test.JoglCanvasTest"
>           CODEBASE = "."
>           width="800" height="600"
>           type="application/x-java-applet;version=1.6"
>           archive="lib/gluegen-rt.jar,
>                    lib/jogl-all.jar,
>                    JoglCanvasTest.jar"
>      </embed>
>    </comment>
> </object>
> </body>
> </html>
>
> I put those two file in the same directory.  I have a subdirectory there
> called 'lib' that there that contains gluegen-rt.jar, jogl-all.jar and the
> appropriate natives jars.  You can either load the html page and run it in a
> browser or run the class as an application directly ("java -cp
> JoglCanvasTest.jar:lib\gluegen-rt.jar:lib\gluegen-rt-natives-macosx-universal.jar:lib\jogl-all.jar:lib\jogl-all-natives-macosx-universal.jar
> test.JoglCanvasTest").
>
> When I open the html page in a browser on OSX 10.6 using Apple's Java 1.6, the
> box is black and in the lower left (this is the error case).
> When I run the applet directly as an application under OSX 10.6 using Apple's
> Java 1.6 the box is red and in the correct location.
>
> Under Windows the box is always in the correct location and is black as an
> applet and red as an application.
> The color difference is because I'm intentionally not doing anything with the
> 'reshape'.
Perfect, thank you for you test, I will include this in our unit tests
and applet test page.

I guess that is OK w/ you ? You may also send me a git patch .. so your
name is preserved in the git history .. as you wish.

~Sven



signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Sven Gothel
Administrator
In reply to this post by jimthev
2 commits:
  http://jogamp.org/git/?p=jogl.git;a=commit;h=9a8f9b9f7e6148b60b6f0f4326df8d213774284c
  http://jogamp.org/git/?p=jogl.git;a=commit;h=3abff83dbc0a99c8d227788c9dddbe59cd15b9ba

'jimthev' and 'Manu' applets are working, as well as vZome test case.

If anybody has a better way to determine location on screen
and the insets, which we need for the CALayer position, please share!

See: http://jogamp.org/git/?p=jogl.git;a=commit;h=3abff83dbc0a99c8d227788c9dddbe59cd15b9ba

Currently building ..

~Sven


signature.asc (911 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Manu
Many thanks Sven.
I'm looking forward to testing this. Can anybody post compiled jars and dlls?
Emmanuel Puybaret
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

hharrison
Looks like the artifacts have popped out the other side:

http://jogamp.org/deployment/autobuilds/master/jogl-b1084-2013-09-27_20-27-51/

Looks to be built from commit ebb62e74f9e0dc87d7632cf16ca1bc7554ffcadc

Harvey
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

jimthev
In reply to this post by Sven Gothel
Yes, you can use the example in your unit tests.  You can do anything you want to with it.

The fixes work!  All my test samples and our full tools work.  A bit more work/testing on our html and deployments locally and then OSX users will be able to run our Java3D programs.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Mac Canvas3D location bug

Manu
It requires also the new build of gluegen available at:
http://jogamp.org/deployment/autobuilds/master/gluegen-b720-2013-09-28_09-10-47/

It works much better.
Miserably, in Sweet Home 3D case, the horizontal position of the canvas 3D is correct but the canvas is shifted vertically of a 20+ pixels towards the top. As soon as I can find how to reproduce the issue, I'll post a unit test.
Emmanuel Puybaret
12345