Results 1 to 3 of 3

Thread: Using QGraphicsScene instead of OpenGL

  1. #1
    Join Date
    Jul 2007
    Location
    California, USA
    Posts
    62
    Thanks
    17
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Using QGraphicsScene instead of OpenGL

    Hello,

    I am currently using openGL to do my image drawing but I thought I would write a test program to see if I could use all QT instead. What I need to do is to display an image that is changing rapidly (up to 64 times a second). I was using glDrawPixels but once I started doing zooming and drawing lines on it, I started to have problems.

    I am crashing deep in fillRect(rr.toRect(), &textureData, d); inside of QRasterPaintEngine::drawImage.

    Am I approaching this wrong? Has anyone gotten this to work? I have put up a test string in the window and that appears so something can appear in my scene.

    I have a class that gets created by my main.cpp and it looks like this:
    Qt Code:
    1. imageTester::imageTester(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4. ui.setupUi(this);
    5.  
    6. m_imageScene = new ImageScene();
    7.  
    8. m_view = new QGraphicsView(m_imageScene);
    9. m_view->show();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Then my imageScene (derived from QGraphcisScene) starts up a timer in the constructor and when the timer goes off, it does the following:


    Qt Code:
    1. if (m_pixmap != NULL) {
    2. removeItem(m_pixmap);
    3. delete m_pixmap;
    4. m_pixmap = NULL;
    5. }
    6. else {
    7. setSceneRect(0,0, w, h);
    8. }
    9.  
    10. unsigned char* displayBuffer = getBuffer();
    11.  
    12. // inside of getBuffer: displayBuffer = (unsigned char*) (malloc ((w*h) * 3));
    13. // and then filled with RGB values for w * h
    14.  
    15. if (displayBuffer != NULL) {
    16. QImage* image = new QImage(displayBuffer, w, h, QImage::Format_RGB32);
    17. QPixmap pixmap = QPixmap::fromImage(*image);
    18. m_pixmap = addPixmap(pixmap);
    19. m_pixmap->setVisible(true);
    20. update();
    21. free (displayBuffer);
    22. }
    To copy to clipboard, switch view to plain text mode 

    Side question: Can I free the image at the end of this method along with displayBuffer?

    Thanks for any help.

  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: Using QGraphicsScene instead of OpenGL

    Don't recreate the item each time you change the image. Simply set the new image on the already existing item. And create the item on stack and not on heap. Apart from that your approach seems fine (although using OpenGL for that is ok too).

  3. The following user says thank you to wysota for this useful post:

    ntp (4th March 2008)

  4. #3
    Join Date
    Jul 2007
    Location
    California, USA
    Posts
    62
    Thanks
    17
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using QGraphicsScene instead of OpenGL

    Here is a followup. Turns out the real problem was that I wasn't allocating enough memory for the incoming image. It needed to be displayBuffer = (unsigned char*) (malloc ((w*h) * 4)); not (... * 3).

    I am using Format_RGB32 but I was focusing on the RGB part and needed to allocate 32 bits and the last 8 bits are used for padding.

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  2. Replies: 3
    Last Post: 12th February 2008, 21:17
  3. QGraphicsScene / QGraphicsView speed after resize
    By themolecule in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2007, 23:46
  4. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  5. OpenGL ES, Qt/11 - Qtopia Core?
    By zelko in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2007, 10:56

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.