View Full Version : Using OpenGL to display DIB (from buffer, not from file!)

04-23-2007, 06:22 AM

I'm writing a program based on VFW to get pics from a webcam. This pics are on DIB format, and stored on a buffer.

Now I want to use OpenGL (through glDrawPixels for instance) to display (I'm using the Qt GUI, and for this I think OpenGL is the best for displaying video).

The thing is that I don't know how to do it. Could anybody give me a hand?


04-23-2007, 08:52 AM
glDrawPixels is pretty simple to use, so I assume you want to know how to create OpenGL context and use it for drawing.
I would start from google'ing for some component. I'm using wxWidgets and there is a GL canvas component. I'm pretty sure someone did something similar for Qt.

04-23-2007, 09:26 AM
Well I have used glDrawPixels before on Qt, to display IplImages (from the OpenCV libraries) and it worked fine.

But I'm trying to use the same concept now and I get no picture.

The thing is that on VFW you use a callback function in which you can get a LPVIDEOHDR structure, as follows:

typedef struct videohdr_tag {
LPBYTE lpData; /* Pointer to buffer. */
DWORD dwBufferLength; /* Length of buffer. */
DWORD dwBytesUsed; /* Bytes actually used. */
DWORD dwTimeCaptured; /* Timefrom start of stream. */
DWORD dwUser;
DWORD dwFlags; /* Flags. */
DWORD dwReserved[4];

And as far as I know, I have to use lpData to display, which is declared as a WORD and supposedly points to a buffer with the new frame on DIB format.

But I don't know exactly what to do so that glDrawPixels works.

I hope I explained mysellf. Thanks!

04-23-2007, 10:08 AM
Blast from the past: Here are some of my post from about seven years ago about doing this from an AVI.
(Cool old forum layout. ;) )

If you have a similar way to get the pointer to the DIB-bits from within VFW that should do the trick.