Results 1 to 5 of 5

Thread: QGraphicsItem and OpenGL textures

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsItem and OpenGL textures

    Hi everyone. I'm fairly new to QT and maybe this is a newbie question. I hope you can forgive me if that's the case.

    I'm writing a application with a diagram editor and I need to display OGL textures in it. At the moment, I roughly follow this process: create a QImage from the texture data, convert this QImage to a QPixmap and use this pixmap in a QGraphicsPixmapItem. This is awfully expensive and inefficient. Any alternatives?

    Should I make my custom QGraphicsItems class and write my own paint() routine using opengl calls?

    Thank you.

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem and OpenGL textures

    You ca set the viewport of your QGraphicsView to use OpenGL with these instructions :
    Qt Code:
    1. setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
    To copy to clipboard, switch view to plain text mode 

    The QGLWiget can also be derived and therefore respond to the GL events, initializeGL, paintGL, ... but I dont know much about it.

    Then to optimize you texture drawing with a QGraphicsItem, you can derive one and overload the paint event in wich you can draw directly from QImage into QPainter.
    But I don't think this will be better once the image is loaded into the QGraphicsPixmapItem.

    S.Cascio

  3. #3
    Join Date
    Sep 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem and OpenGL textures

    I already set the viewport to use OpenGL and speed up the rendering.

    Then to optimize you texture drawing with a QGraphicsItem, you can derive one and overload the paint event in wich you can draw directly from QImage into QPainter.
    But I don't think this will be better once the image is loaded into the QGraphicsPixmapItem

    I don't want to create a QImage or a QPixmap if I don't need to. Can I draw the loaded OGL texture overloading the paint event of a QGraphicsItem and using OGL calls? Do I have to make my custom QGLWidget and add it to the scene?
    Last edited by Aldebaran; 18th September 2009 at 10:41. Reason: spelling error

  4. #4
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem and OpenGL textures

    In a QLWidget you can make OGL calls. I have no experience on it but the doc may show yiou the way.

    If you want to derived a QGraphicsItem that manages an OGL texture, you can use QImage as a wrapper of a buffer of char, to prevent from copying texture data. Then it is easy to draw it with in painter. QPainter::draw can draw a part of the image inside a part of your item, doing the scaling automatically, without any pre computed transformation.

    S.Cascio

  5. #5
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsItem and OpenGL textures

    I have a related question. I would like to operate with quite a lot (between a few 100 and a few 1000) small items which I would like to draw using OpenGL. To draw them, I need to be able to do one of the following two things:
    - specify own texture coordinates for the drawn item
    - change the uniform shader parameters of the current shader (all of them can use the same shader)

    The item geometry itself can be as simple as a rectangle. Traditionally, I would just have used a QGLWidget, but I recently read about GraphicsView and GraphicsItems. Will it be beneficial for me to use those in my case? I couldn't really find any information about how to achieve either of the above points, unless I use beginNativePainting which I believe will be slow for hundreds to thousands of items since the entire OpenGL would be copied for every drawn item (as far as I understand).

    Thanks
    - Dominik

Similar Threads

  1. opengl help!!
    By rachana in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2007, 08:52

Tags for this Thread

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.