3

I have a SDL_surface that plays a video in its own window. I want this window to be rendered on a QWidget. I want a generic solution because my targets are OSX, Windows and Linux.

I've come across 2 solutions summarized as below:

  1. The Window ID hack involves setting SDL_WINDOWID to the QWidget's id so SDL pushes pixels on the QWidget. Here is an Example Qt snippet from a related thread.

    However, this doesn't work on OS X and is not guaranteed to work on all Win and Linux platforms.

  2. Manually copying from non-window SDL_surface to QWidget.

    Found some example code for Gtk+ but nothing for Qt so far. The idea is to push the video to memory and pull it from QWidget. Surely one shouldn't use a QImage to render each frame. So how would one implement this copying?

There are possible duplicate questions but my question is more specific about platform-independence

Community
  • 1
  • 1
S B
  • 8,134
  • 10
  • 54
  • 108

1 Answers1

2

Retrieve the pixels from the SDL_Surface and create a QImage with it, then use a QPainter to draw the QImage on the widget.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Won't the overhead associated with creating a QImage make it inefficient, like I said in my question? – S B Jun 28 '12 at 07:27
  • I don't have any, but I might write some later today. But your question is not tagged as C/C++ ... – karlphillip Jun 29 '12 at 12:31
  • I'm trying to code it as well. Will update [this question](http://stackoverflow.com/questions/11261275/efficient-conversion-from-sdl-surface-to-qpixmap) when I'm done, if you are interested – S B Jun 29 '12 at 12:51
  • Just to be clear, there's really no conversion of data going on in the approach I suggest. The bottleneck is really drawing the stuff on the screen. =/ To make it faster, [render the data to a `QGLContext` instead](http://stackoverflow.com/questions/11194604/high-performance-qimage-output-to-display/11194780#11194780). – karlphillip Jun 29 '12 at 13:44
  • You mean when I initialize QImage, it doesn't deep copy the RGB array? Or you meant that such a memory copy is not intensive anyway? – S B Jun 29 '12 at 16:53
  • 1
    FYI got [an answer](http://stackoverflow.com/a/11261901/492857) to how to transform SDL_Surface to QImage. It's working. Thank you for pointing me in the right direction – S B Jun 29 '12 at 16:55