Results 1 to 6 of 6

Thread: OpenGL rendering problem

  1. #1
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default OpenGL rendering problem

    I have a project where I render a recorded gps path on an aereal photo. I do this using a QGraphicsScene with a QGraphicsPathItem on a QGraphicsPixmapItem. Simple enough. When I use OpenGL to render the scene, i.e.
    Qt Code:
    1. QGraphicsView::setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
    To copy to clipboard, switch view to plain text mode 
    i notice that the path loses accuracy, as if it is restricted by a lower resolution. See the attached snapshots. Does anybody have an idea why this is, or how i can fix it?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: OpenGL rendering problem

    Is the scene size the same in both cases? Could you prepare a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL rendering problem

    I think that the problem is using the antialiasing (multisample buffers).

  4. #4
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: OpenGL rendering problem

    OK, now I've gotten around to preparing a minimal example. You can see the problem by turning on gl rendering and zooming in with the wheel mouse. Look at the top and bottom of the circle to see the effect.

    Explanation:
    I have a georeferenced image with the accompanying data:
    Qt Code:
    1. 0.250000
    2. 0.000000
    3. 0.000000
    4. -0.250000
    5. 400000.000000
    6. 6000000.000000
    To copy to clipboard, switch view to plain text mode 
    which means the image origin is at (400000, 6000000) (central europe) and the pixel size is 0.25 x 0.25 meter (y axis flipped).
    My problem stems from deriving the scene rect from the data. It's pretty handy to know that one unit in the scene corresponds to one meter in the real world.
    so I add the image as a QGraphicsPixmapItem

    Qt Code:
    1. QGraphicsPixmapItem*item = new QGraphicsPixmapItem(QPixmap::fromImage(img), 0, &scene);
    2. QMatrix matrix;
    3. matrix.translate(400000.0, 6000000.0);
    4. matrix.scale( 0.25, -0.25);
    5. item->setMatrix(matrix);
    6.  
    7. // set sceneRect to image size
    8. scene.setSceneRect(matrix.dx(), matrix.dy(), img.width()*matrix.m11(), img.height()*matrix.m22());
    To copy to clipboard, switch view to plain text mode 

    I then want to display a recorded gps path. I have two ways of doing this. One which shows up ok and one which displays the aforementioned problem.

    Qt Code:
    1. // doesn't work with opengl
    2. path.lineTo(p1);
    3. path.lineTo(p2);
    4. ...
    5. QGraphicsPathItem*pathItem = new QGraphicsPathItem(path, 0, &scene);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // works with opengl
    2. QPointF origin(400000.0, 6000000.0);
    3. path.lineTo(p1-origin);
    4. path.lineTo(p2-origin);
    5. ...
    6. QGraphicsPathItem*pathItem = new QGraphicsPathItem(path, 0, &scene);
    7. pathItem->moveBy(origin.x(), origin.y());
    To copy to clipboard, switch view to plain text mode 
    Obviously there is some kind of a rounding error at work here. The problem is worse along the y-axis, which makes sense, since the offset in that direction is larger by a factor of 20.

    I now know how to work around this problem, but I am curious as to why it shows up in one case and not the other and if it is a necessary evil dictated by technical limitations or a bug in the Qt implementation.
    Attached Files Attached Files

  5. #5
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL rendering problem

    I was looking at the QT source code to find where is the problem when there is a rendering in OpenGL. Before rendering the path, QT tesselates the "path" into the triangles, then renders the triangles into to OpenGL. Maybe the tesselator is the problem? Qt uses GLU tesselator, maybe GLU tess losses accuracy?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: OpenGL rendering problem

    If you're zooming, then it might be a problem with floating point calculations accuracy. Does the same thing happen with smaller zoom factors?

Similar Threads

  1. OpenGL glGet problem
    By Cloudy in forum General Programming
    Replies: 1
    Last Post: 27th December 2006, 00:10
  2. basic qt opengl problem
    By kingslee in forum Qt Programming
    Replies: 4
    Last Post: 12th November 2006, 16:26
  3. Qt 4.2.0 OpenGL problem
    By mbjerkne in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2006, 19:39
  4. Rendering problem
    By boss_bhat in forum Qt Programming
    Replies: 1
    Last Post: 20th June 2006, 09:48
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.