Video?!?!?..........Embedded in OpenGL????

Here is a question for those that like a challenge…

Can video (AVI, MPEG etc.) be embedded into a 3D scene? If so, how?

Thanks for any contributions,

Gus.

http://www.ati.com/na/pages/resource_cen…ectedVideo.html

Oops. Just realized that’s using DirectX7. Well, have a look and see if it’s applicable to GL.

Glossifah

[This message has been edited by Glossifah (edited 01-15-2001).]

Thanx… Checked it out, but as mentioned, is for DirectX7 only.

I want to be able to play a video clip on the television I’ve modelled in my walkthrough. Any suggestions???

Cheers… Gus!

If you’re developing on a Mac or PC, you should consider QuickTime as an option. You can generate texture maps from any video source that is QuickTime compatible (which these days includes just about everything). Apple has (last I checked) demos of mapping video onto 3D objects at their website… dig around http://quicktime.apple.com/ to find the goods.

Hello!

If the resolution of the video is low you could render the images one after one into a large® texture map and then just change the texuter coordinates. For example if the separate images are 64x64 pixels then you could render them into a texture map which is 1024x1024, and that’ll give you 256 separate frames, and that could maybe be almost 20 seconds of video at 13 fps…

Just my 2 cents…

Osku

Sorry for the shameless plug, but you need to visit my website :slight_smile:

Using DirectShow: http://www.gamedeveloper.org/delphi3d/download/VideoTex.zip
Using VFW: http://www.gamedeveloper.org/delphi3d/projects/u3d/files/demos/vid2tex.zip

Those are both Delphi code, but you should be able to figure it out. I’m not sure if those demos include an executable though - let me know if you need one.

  • Tom

Thanks for your help guys,

The link to your Video for Windows example look especially interesting. Could you please post an exec. becuase it would be rather useful. I’ll try converting the code from Delphi to C, so I can include it in my walkthrough.

Help much appreciated…

Gus.

Well I wrote a small library that extracts the images of an AVI file frame by frame.I then wrote a small OGL app that renders the video frames to a polygon using the glTexSubImage2D() function and it all works really well

Oh this brings me to my question…
In my test app I’m using 4 quads and I’m rendering the same video to all of them.But I’m only getting around 48 frames per second on a GeForce2 card :stuck_out_tongue: Is that normal or am I doing something wrong? The speed increases when I use less quads (which is understandable) but still,you’d think a GeForce2 card would give a much higher performance.Maybe it’s something in my code.
Here’s a little snippet that extracts the next frame from the AVI and then texture maps it to the quad:

glPushMatrix();
glTranslatef(0.0,0.0,-3.0);
glScalef(6.7,5.0,0.0);
glBindTexture(GL_TEXTURE_2D, AVIVideo);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,pDSV2->DSVGetInfo(DSV_WIDTH),
pDSV2->DSVGetInfo(DSV_HEIGHT),GL_BGR_EXT,GL_UNSIGNED_BYTE,
pDSV2->DSVGetFrame(loop));
glCallList(DSVList);
glPopMatrix();

This is for just one of the quads…the other 3 quads are spinning around on different axis.Any thoughts?

Oh Gus: If you need any help with this or if you need the source code then drop me an email at: thegecko@tbaytel.net Hopefully this is what you’re looking for.

DOH nevermind! I got it working up to 90fps now!!! That was really stupid. You see, all those quads were the same display list and what I was doing was updating the texture over and over again 4 times for each quad instead of updating it once and just binding the new updated texture once for all the quads :stuck_out_tongue: (Does that even make sense?!) Anyway I got it working much faster now.GOD I love OGL!

So now my main loop looks like this: (I know I should be using Ortho projection for the rear quad but I’ll fix that later)

GLvoid DrawGLScene(GLvoid)
{
//This is where all the “magic” happens.This is the function where
//we will keep reading in data from our AVI file and display that
//data as a texture onto our square.

if(loop >= pDSV2->DSVGetInfo(DSV_FRAMES))
loop=0;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear The Screen And The Depth Buffer
glLoadIdentity();// Reset The View

//Move the scene back 9 units
glTranslatef(0.0f,0.0f,-9.0f);

//Bind the updated video texture to our Quads
glBindTexture(GL_TEXTURE_2D, AVIVideo);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,pDSV2->DSVGetInfo(DSV_WIDTH),
pDSV2->DSVGetInfo(DSV_HEIGHT),GL_BGR_EXT,GL_UNSIGNED_BYTE,
pDSV2->DSVGetFrame(loop));

//Rotate and translate our leftmost square
glPushMatrix();
glTranslatef(-3.0,0.0,0.0);
glRotatef(angle,0.0,1.0,0.0);
glCallList(DSVList);
glPopMatrix();

//Rotate our middle square
glPushMatrix();
glCallList(DSVList);
glPopMatrix();

//Rotate and translate our rightmost square
glPushMatrix();
glTranslatef(3.0,0.0,0.0);
glRotatef(angle,1.0,0.0,0.0);
glCallList(DSVList);
glPopMatrix();

//Translate and scale our back square
glPushMatrix();
glTranslatef(0.0,0.0,-3.0);
glScalef(6.7f,5.0f,0.0f);
glCallList(DSVList);
glPopMatrix();

//update our counters
if(angle > 360.0)
angle = 0.0;

angle += 2.0;
loop++;

Timer.Frame();

fontSize(10);
fontColorA(0.0,0.5,1.0,0.5);
fontDrawString(0,SCREENY-10,“FPS: %f
FRAME#: %i/%i”,Timer.GetFps(),loop,(int)pDSV2->DSVGetInfo(DSV_FRAMES));

glColor3f(1.0,1.0,1.0);

}

I’m so happy

[This message has been edited by TheGecko (edited 01-17-2001).]

TheGecko,

When you say this snippet is for ONE quad, do you mean this snippet is called 4 times (once for each quad) with a different positioning ???

I mean, do you call 4 times glBindTexture()+glTexSubImage2D() ???

If yes, do the following:

glBindTexture();
glTexSubImage2D(); // You use the same video/frame for the quads ! //
RenderQuad1();
RenderQuad2();
RenderQuad3();
RenderQuad4();

If you are already doing this, then I cannot see any problem!

Regards.

Eric

Originally posted by TheGecko:
DOH nevermind! I got it working up to 90fps now!!! That was really stupid. You see, all those quads were the same display list and what I was doing was updating the texture over and over again 4 times for each quad instead of updating it once and just binding the new updated texture once for all the quads :stuck_out_tongue: (Does that even make sense?!) Anyway I got it working much faster now.GOD I love OGL!

Erm, that happens to me quite often: answering a question at the same time than somebody else !

Anyway, that was the solution !!!

Regards.

Eric

Heh yeah…It’s amazing all the optimisations you can do when you look back at your old code.

I see what you guys are saying. I whole heartedly agree.

The code actually looks quite interesting. Would it be possible to obtain the source code? It would be a great to add to my research.

Thanks for all your help guys…

Gus.

I just sent ya a little project to show you how to use that glTexSubimage2D() function. Beware though it’s a bit messy since I’ve coded this a year ago and I’ve learned ALOT since then Enjoy!

Thanks a lot… You’ve been great!

Gus.

Hi,

I’m also looking to play movies in a 3d application. Did find a way to do that ?

Thanks a lot for help.

Originally posted by Gus:
[b]Here is a question for those that like a challenge…

Can video (AVI, MPEG etc.) be embedded into a 3D scene? If so, how?

Thanks for any contributions,

Gus.

[/b]

good ol’ NeHe : http://nehe.gamedev.net/tutorials/lesson36.asp

There is a bit more advanced way how to do that:
Look at showstrm sample form older DirectShow
SDK and on the Lock property of DirectDraw
surface. It is possible to transfer a DirectShow
generated DirectDraw surface into an OpenGl
texture by combinatio the above ideas.
The result will be in this cas not only AVI
but even DirectShow compatible (with mpeg,
DV, ASF …) . I have made a comercial code based on this idea,
I can not give you sources, but it works …