OpenGL without QGLWidget?



  • Gentlefolk -

    Perhaps this is sacrilegious, but I would like to use OpenGL in a Qt program, without using the QGLWidget. Initially, this would be in Windows, but eventually on OS X as well. Does anyone have any trivial example code that they'd be willing to toss my way? Have searched around quite a bit, and just cannot find anything...

    Thanks!



  • Sorry, I don't understand your problem fully.

    If you are meant to use OpenGL without using Qt OpenGL module, it would be complex.

    If you are meant to use OpenGL native command in QWidget rather than QGLWidget, how about QPainter::beginNativePainting()?
    "http://doc.qt.nokia.com/stable/qpainter.html#beginNativePainting":http://doc.qt.nokia.com/stable/qpainter.html#beginNativePainting

    But you still have to set QGLWidget for viewport anyway.



  • May be link below can be helpful too
    "Tutorial":http://www.cs.uccs.edu/~semwal/indexGLTutorial.html



  • [quote author="diro" date="1321586303"]Sorry, I don't understand your problem fully.

    If you are meant to use OpenGL without using Qt OpenGL module, it would be complex.

    If you are meant to use OpenGL native command in QWidget rather than QGLWidget, how about QPainter::beginNativePainting()?
    "http://doc.qt.nokia.com/stable/qpainter.html#beginNativePainting":http://doc.qt.nokia.com/stable/qpainter.html#beginNativePainting

    But you still have to set QGLWidget for viewport anyway.[/quote]

    I want to be able to use OpenGL inside a widget, with no involvement whatsoever of the QOpenGLWidget. I have used the QOpenGLWidget extensively, but the "favors" it does come at a price. Hence, the motivation.

    One should be able to obtain the Window-system-specific window (e.g. HWND on Windows), set up an OpenGL context appropriately, and then call OpenGL functions in the paint method. Unfortunately, when I've done this, I get nothing displayed. Surely this is just some simple error, and in truth, I've not spent a lot of time trying to figure out what I've done wrong. Hence, my question :-)

    Perhaps this native painting scheme might do the trick, but I don't understand your last comment about having to use a QOpenGLWidget to set the viewport - I can get the window's size from any QWidget, and so I should be able to set the OpenGL viewport with that info, right?

    I was hoping I could just obtain a simple "Hello, world" type program from someone who's already figured this out :-)

    In any case, thanks much for your response...

    -- Philip



  • What exactly is your motivation not to use QGLWidget? Portability? I assume you're using Qt's other services anyway (loading textures etc) so what's the harm in using QGLWidget?

    For reference, I wrote an OpenGL app that uses only portable standard OpenGL (none of those classes provided by Qt such as QGLShaderProgram) and QGLWidget just to provide the OpenGL context. I put 90% of my code in portable C++ and use a following class setup:

    @class MyPortableOpenGlStuff { .. }

    class MyGLWidget : public QGLWidget, public MyPortableOpenGlStuff { .. }@

    To port the software, only stuff such as the context + image loading would have to be rewritten. And since most of the platforms run Qt code (damn you Apple, thank you Necessitas) nicely, I havent even had to port anything yet..

    • Matti

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.