Time-Shift: Veritas liberabit vos
The truth shall set you free

Plasma Applets and OpenGL

I lately tried to implement an Plasma Amarok Applet that has an OpenGL Widget inside of it. One would think this is a rather easy task since all this new and fancy KDE Plasma stuff smells a lot like OpenGL. Sadly not by a long shot. Implementing an OpenGL Plasma widget normally works this way: create a widget, set the Viewport of the Graphics view to an new QGLWidget and you got it. This approach has 2 Downsides though: first of all if you Viewport is an QGLWidget all you drawing will be rendered via OpenGL. And not only on this applet but on all Applets that share this widget. One might think this is no Problem. But OpenGL handles a lot of stuff quite different then the Qt Implementations of the Graphics Objects. For starters colors. The same color values won’t give you the same output if one is rendered by OpenGL and the others by Qt. So you get strange colors all over the place (and not only in this particular applet but in all the others, because all Amarok Applets share one Viewport). The second problem with this approach is that it will make rendering of non OpenGL stuff and OpenGL stuff at the same time quite hard. You’ve got to watch out for what you’re painting when and in what order and a lot of OpenGL functionality will have to be left untouched because it would mess with you Non OpenGL windows etc. As you might have guessed this was not an acceptable solution. All other approaches I made (render into the QGLWidget and get the Framebuffer from there for example) ended in either an empty Widget or a separate window for my OpenGL stuff. Googleing my ass of and tyrannizing a lot of nice people on IRC finally got me the “right” answer to my problem: I had to render all the OpenGL stuff into a QGLPixelBuffer and then paint this buffer onto the Widget with all the other Graphics Objects. Insane? Definitely! But it works like a charm. And know what? Its quite fast and reliable. I even got it to paint either to a separate Window, the Widget or even fullscreen just by clicking a button. Looks like we’re living in an insane world after all :-P.

2 Responses to “Plasma Applets and OpenGL”

  • […] applet for Amarok. The applet will benefit from my OpenGL applet template I made a few days ago (see this Post). This way it will also have all the nice functionality the template has (like switching between […]

  • Lea says:

    Unfortunately, I’m not very qualified as to work on such helpful projects for society like Amarok.
    Therefor I have to admire you all the more for your wide variety of capacity concerning every little
    area of programming. It’ isn’t easy for me to imagine how to be so competent on all data processing
    matters and to enrich people with useful programms you have already written for me too.
    So I have to avail myself of the opportunity of thanking you and to say that I’m very proud of you,
    my darling.

    yours

  • Leave a Reply to Amarok Spectrum Analyzer « Time-Shift: Bonus vir semper tiro Cancel reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.