Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: Drawing standard widgets using a custom paint engine

  1. #21
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drawing standard widgets using a custom paint engine

    Something like

    Qt Code:
    1. #IFDEF Q_OS_WIN
    2. HGLRC rc = wglGetCurrentContext();
    3. #ELSE
    4. GLXContext rc = glXGetCurrentContext();
    5. #ENDIF
    To copy to clipboard, switch view to plain text mode 

    in the intializeGL() or paintGL() methods of a QGLWidget will probably get the necessary rendering contexts. I've proved the Windows leg first with an OpenCascade OpenGL viewer - the alternate piece is the logical extension for X11.

    Pete

  2. #22
    Join Date
    May 2007
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing standard widgets using a custom paint engine

    Thanks for that tip; I'll look into it at some point.

  3. #23
    Join Date
    May 2007
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing standard widgets using a custom paint engine

    That did indeed work, and I've managed to make a subclass of QGLWidget which embeds Ogre as its background, allowing me to use Qt paint calls on top of an Ogre context, with alpha compositing, and to use this as a QGraphcsView viewport - using the bare minimum of Xlib and GLX calls to glue it all together .
    I might post a bit more on this once it's tidied up, but on the other hand I kind of doubt anybody will care...

  4. #24
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing standard widgets using a custom paint engine

    oh, we care!
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #25
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drawing standard widgets using a custom paint engine

    I care too, especially as you've just tested a line of code that I couldn't.

    Pete

  6. #26
    Join Date
    May 2007
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing standard widgets using a custom paint engine

    Well I've got a simple Ogre widget, and a corresponding GraphicsView widget, along with a couple of subclasses for those implementing some more demonstrative functionality, and finally a simple demo app, mixing Qt and CEGUI (not sure why you'd want to in reality, but anyway...)

    If you're not interesting in building the Ogre demo, the most important bit of code to look at is probably in QOgreGLWidget::initializeGL().

    The idea is to get Ogre to use an existing window (which requires that you know its XVisualInfo), and to switch between QGLWidget and Ogre GLXContexts at the appropriate times so neither find themselves in an unexpected state.

    The final point is to ensure that both Ogre and Qt don't try to swap buffers; I let Qt do it so that the QGLWidget can get a chance to draw over the window after Ogre's done with that frame.

    Apologies for the roughness; I got bored of tidying it all up :P.

    Also, I think there was something else I was planning to add to this post, but it's two in the morning so I'll see if I remember tomorrow...
    Edit: I think it might have been that there's a bug in Ogre which this triggers. Nothing desperate - you get X Errors when the widget is destroyed; I've provided a patch.

    (Just noticed that CEGUI widgets, including the mouse cursor, are resized along with the window. Text correctly manages to remain the same size though and I'm performing the resize notifications to CEGUI in the same place, so I don't see what's wrong. Guess I must have missed something.)
    Attached Images Attached Images
    Attached Files Attached Files

  7. The following 2 users say thank you to Waywocket for this useful post:

    aMan (16th October 2007), desert (21st October 2010)

  8. #27
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    1

    Default Re: Drawing standard widgets using a custom paint engine

    I've been doing some research and this is the closest i've found on Qt+OGRE shared OpenGL rendering.

    But have you found a way to share the context instead of switching? Context switching might be costly. Have you read about

    Qt Code:
    1. params["externalGLContext"] = Ogre::StringConverter::toString( ((unsigned long)(glXGetCurrentContext()) ) );
    2. mRenderWindow = mOgreRoot->createRenderWindow("View", width(), height(), false, &params);
    To copy to clipboard, switch view to plain text mode 

    Im doing this but seems OGRE insists on creating a new context.

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
  •  
Qt is a trademark of The Qt Company.