PDA

View Full Version : Video player with libVLC and glDrawPixels flipped



alb84
03-01-2010, 07:24 AM
Hello, I need to write a OpenGL code for an accademic project, to overlay cartography information over a video coming from a plane.
The cartography is available as a DXF and can be easily loaded in a GL 3D world.
The camera position and orientation should be derivable from GPS information mounted on the plane.

I just want an advice to set up the project in order to make something working possibly real time and usable.

Unfortunately I have to use Winforms, but I found a good example showing how to integrate OpenGL with .NET managed Winforms
http://www.codeproject.com/KB/miscctrl/OpenGLViewWinForms.aspx

I have also integrated dxflib to load the DXF and libVLC to receive the video stream.

In particular libVLC is offering a media player instance whose initialization takes a callback address to a function libVLC will call after the decoding of each frame, and a buffer address where libVLC will store the pixel data in 32 bit BGRA.

So in this callback I call


glDrawPixels(VIDEO_WIDTH, VIDEO_HEIGHT, GL_BGRA,
GL_UNSIGNED_INT_8_8_8_8, (void*)pixelData);


This is working fine, the video playing is working fine and real time, the CPU usage is very low... yet the video is vertically flipped.

So before glDrawPixels I tried to call


glRasterPos2i(0, VIDEO_HEIGHT); // also tried glRasterPos2i(0, 0);
glPixelZoom(1, -1);

but it does not work. With these two lines before glDrawPixels I see just the first video frame, again vertically flipped, and then the video does not change, but the CPU usage is still very low.

Another problem I encountered is that, flipped or not flipped, I want OpenGL to draw over my video, so immediately after glDrawPixels I call



glLoadIdentity();
glTranslatef(...);
glRotatef(...);
glBegin(GL_TRIANGLES);
. . .
glEnd();


but I see only the video frame.

Yet, if I replace glDrawPixels with glClear I see polygons on black background.


Can you help me or advice me some better solution for my project?
What I need is drawing polygons on a video stream instead of drawing polygons on a black background.

ZbuffeR
03-01-2010, 08:45 AM
Instead of a simple drawpixels, I would instead put the data in a texture, then it is very easy to flip a textured quad.

It will help for the second problem too, as my guess is the depth is off, so new triangles do not pass the depth test. You can also try with depth-only clear.

alb84
03-01-2010, 09:02 AM
You are saying to use a texture instead of drawpixels? I thought drawpixel was faster and simpler...

If I use a texture, for my application, where the cartography is my still world, and the camera moves, then I need to move the texture so that it is always in front of the camera and always normal to the camera axis... isn't that a bit useless?

Anyway the second problem was solved by clearing the depth buffer, many thanks!

Any other solution and or explanation for the first problem?

ZbuffeR
03-01-2010, 09:32 AM
Check "9. Careful Updating that Raster Position" here :
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

alb84
03-01-2010, 10:01 AM
Thanks, I added this line


glOrtho(0, width, 0, height, -1, 1);

before glRasterPos and now it works fine!

Since you've been so gentle, can you just explain or give me some links to understand how to move the camera leaving the loaded world where it is and leaving the video drawn with DrawPixel where it is?

Since I am also worried about performance issues it would be great to understand how to use GLlists to simplyfy the deformation of the cartopgraphy as much as possible...

ZbuffeR
03-01-2010, 10:13 AM
What do you mean exactly by "move the camera leaving the loaded world where it is" ? glTranslatef ?

Basically with GL you don't leave stuff where it is, you just clear and draw it at another place.

Same for the video, that is why I talked about using a textured quad, it is easier to manipulate, scale, rotate, etc.