Results 1 to 5 of 5

Thread: QGraphicsView and fast moving objects

  1. #1
    Join Date
    Jan 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsView and fast moving objects

    Hi,
    I've been making a pong clone using a QGraphicsView, but i seem to have an issue with moving objects rapidly within the view e.g. the ball, which i have updating around 40Hz.

    1/ it's blurry.. I expect abit of blur because of the movement, but it seems as if the ball is being painted in it's new position, before the old position has been repainted, ie for an instant it's in two places at once. It makes it kinda difficult to focus (literally) on the ball, though some of this may be subjective.

    2/ there's tearing/artifacting. not all the time, but if you watch the ball for 10s or so you'll see it.

    I've tried playing around with different caching modes, on both the ball graphicsItem and the graphicsScene itself, but with little success. I've also tried disabling the viewport updates and managing the updating myself, but the same problems occur.

    I've included a sandbox example of a ball bouncing around so you can check it out (only compiles for windows, sorry), i must be doing something obvious wrong, as i know GV can handle thousands of items, surely it can handle one fast ball?!
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2009
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView and fast moving objects

    hi guys, any suggestions I can try here?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsView and fast moving objects

    Perhaps turning of scene's item index method helps a bit?
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView and fast moving objects

    Did you experiment with OpenGL to make use of the graphics card processor?

    From QGraphicsView:

    By default, QGraphicsView provides a regular QWidget for the viewport widget. You can access this widget by calling viewport(), or you can replace it by calling setViewport(). To render using OpenGL, simply call setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport widget.

  5. #5
    Join Date
    May 2008
    Location
    duesseldorf, germany
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView and fast moving objects

    first of all: when using Qt, please prefer using its methods above using platform dependent stuff.
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QDebug>
    3. #include "balltest.h"
    4. #include <QTime>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. Balltest w;
    10. w.setGeometry( 200, 200, 1024, 768 );
    11. w.show();
    12. QTime prevTime = QTime::currentTime();
    13. while( w.IsRunning() )
    14. {
    15. if( (prevTime.msecsTo(QTime::currentTime())) >= 0.025 )
    16. {
    17. w.Update();
    18. prevTime = QTime::currentTime();
    19. }
    20. a.processEvents();
    21. }
    22. return 0;
    23. }
    To copy to clipboard, switch view to plain text mode 
    works on any platform (even though I'd recommend to use a QTimer firing regularly !)

    Looked on your code and tried on X11, the "problem" is simply due to the fact that the screen updates are based upon rectangular areas which are repainted one after each other, so depending on the platform / gfx card / driver / processor you'll get more or less tear and flicker.
    With OpenGL you'll at least circumvent this partially, because GL renders into an offscreen buffer which is switched after all paint operations are done.
    You will still have tearing, which occurs due to the fact that you're changing the screen contents just while it's being displayed, but you can get rid of this when waiting for VBlank (can be adjusted in most graphic card drivers).

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.