Announcement

Collapse
No announcement yet.

Incorrect handling for DPI Scaling.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Incorrect handling for DPI Scaling.

    I'm using Java 11, and set of JOGL jar files I built from source, pulled 3/19/2023.

    Symptom: cursor position reports are different for the same location on the globe when the Windows DPI scaling is changed. It's easy to see the problem with any of the examples that show the mouse pointer coordinates in the status bar. Pick some position on the globe that's easy to identify. Get the mouse pointer coordinates with DPI scaling set to 100%. Then restart the application after changing the scaling to 125%. The reported coordinates for the globe location will be different.

    I'm not sure what the correct terminology should be to refer to the different screen coordinates. See https://learn.microsoft.com/en-us/ar...-in-windows-10. I think in WorldWind, when the term AWT screen coordinates is used, it's referring to "effective pixels". The drawing surface in OpenGL uses "physical pixels", and that's what will be returned by GLCanvas.getSurfaceWidth() and GLCanvas.getSurfaceHeight().
    When an AWT event is received that has display coordinates, those are the effective screen coordinates. So if DPI scaling on Windows is set to 125%, and AWT returns a cursor position of (100,100), the screen physical coordinates will be (125,125).

    The viewport returned by OpenGL uses the physical coordinates. WorldWind picks it up in BasicOrbitView:

    // Get the current OpenGL viewport state.
    int[] viewportArray = new int[4];
    this.dc.getGL().glGetIntegerv(GL.GL_VIEW PORT, viewportArray, 0);
    this.viewport = new java.awt.Rectangle(viewportArray[0], viewportArray[1], viewportArray[2], viewportArray[3]);

    The screen physical coordinates are also referred to as "surface" coordinates in the WorldWind code.

    Mostly, WorldWind handles this correctly. But it doesn't with pick object positions. There are at least two places in the code where the GL viewport coordinates are mixed with local coordinates without appropriate scaling. Probably gov.nasa.worldwind.render.DrawContextImp l needs rework, and anywhere DrawContextImpl.getPickObject() is called is suspect.

    Consider:

    public int getPickColorAtPoint(Point point)

    // Translate the point from AWT screen coordinates to OpenGL screen coordinates.
    Rectangle viewport = this.getView().getViewport();
    int x = point.x;
    int y = viewport.height - point.y - 1;

    But here, the viewport height is in screen coordinates, and 'point' is in local coordinates.

    Here's another example:

    public void addPickPointFrustum()
    {
    //Compute the current picking frustum
    if (getPickPoint() != null)
    {
    Rectangle viewport = getView().getViewport();

    double viewportWidth = viewport.getWidth() <= 0.0 ? 1.0 : viewport.getWidth();
    double viewportHeight = viewport.getHeight() <= 0.0 ? 1.0 : viewport.getHeight();

    //Get the pick point and translate screen center to zero
    Point ptCenter = new Point(getPickPoint());
    ptCenter.y = (int) viewportHeight - ptCenter.y;
    ptCenter.translate((int) (-viewportWidth / 2), (int) (-viewportHeight / 2));

    The coordinates that 'getPickPoint()' returns are in local space, but the GL viewport is in screen coordinates.

    The pick point location gets set directly from the AWT event, something like:

    Thread [AWT-EventQueue-0] (Suspended (breakpoint at line 182 in AbstractSceneController))
    StereoOptionSceneController(AbstractScen eController).setPickPoint(Point) line: 182
    AWTInputHandler.mouseMoved(MouseEvent) line: 566
    WorldWindowGLCanvas(Component).processMo useMotionEvent(MouseEvent) line: 6680
    WorldWindowGLCanvas(Component).processEv ent(AWTEvent) line: 6404
    WorldWindowGLCanvas(Component).dispatchE ventImpl(AWTEvent) line: 5011
    WorldWindowGLCanvas(Component).dispatchE vent(AWTEvent) line: 4843
    EventQueue.dispatchEventImpl(AWTEvent, Object) line: 772



    See also: https://forum.worldwindcentral.com/f...ution-monitors

    Last edited by gbburkhardt; 03-20-2023, 02:28 PM.

  • #2
    If DPI Scaling issue only occurs with some specific apps, check to see if there is an update or special setting for that application to better support DPI Scaling. aa route planner

    Comment


    • #3

      DPI scaling issues can occur when the display settings on a computer are not configured properly, connections leading to incorrect rendering of text, images, and interface elements.

      Comment

      Working...
      X