🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

how to display AVI in Lesson 30

Started by
3 comments, last by azstevep 14 years, 7 months ago
I'm new to openGL and have been successfully playing with and modifying both Lesson 30(3D collisions) and Lesson 35 (playing AVI). Next I want to merge the two by playing an AVI file in a small section of the overall display while the spheres move around. I created a functions InitiliazeAVI() and DrawAVI() to setup and handle the AVI functions. I inserted DrawAVI() inside DrawGLScene() of Lesson 30. The end result is that I only get a gray box in the center of the display. I'm sure this is easy, but I could use some assistance. void DrawAVI() { // Clear Screen And Depth Buffer glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Grab A Frame From The AVI GrabAVIFrame(frame); if(bg) // Is Background Visible? { glLoadIdentity(); // Reset The Modelview Matrix glBegin(GL_QUADS); // Begin Drawing The Background (One Quad) // Front Face glTexCoord2f(1.0f, 1.0f); glVertex3f( 11.0f, 8.3f, -20.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-11.0f, 8.3f, -20.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-11.0f, -8.3f, -20.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 11.0f, -8.3f, -20.0f); glEnd(); // Done Drawing The Background } glFlush(); // Flush The GL Rendering Pipeline }
Advertisement
We need to see more of your code to be able to give you proper solutions, but my first guess is that you're clearing the color and depth buffer twice each frame.

You only need glClear(..) once at the beginning of DrawGLScene?!
This is my new version of DrawGLScene(). At the top, I call DrawAVI(). With this code, I am able to see the avi, but it is flashing. It's almost as if there is no synchronization. I've played with putting DrawAVI is various places, but nothing seems to help.

Thanks!

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
int i;
static float offset = (float)0.01;
//====================================
// Call Video
//====================================
DrawAVI ();// Draw Our Scene

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//set camera in hookmode
if (hook_toball1)
{
TVector unit_followvector=ArrayVel[0];
unit_followvector.unit();
gluLookAt(ArrayPos[0].X()+250,ArrayPos[0].Y()+250 ,ArrayPos[0].Z(), ArrayPos[0].X()+ArrayVel[0].X() ,ArrayPos[0].Y()+ArrayVel[0].Y() ,ArrayPos[0].Z()+ArrayVel[0].Z() ,0,1,0);

}
else { gluLookAt(pos.X(),pos.Y(),pos.Z(),up_pos.X()+dir.X(),up_pos.X()+dir.Y(),up_pos.Z()+dir.Z(), 0.0,1.0,0.0);
}

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glRotatef(camera_rotation,0,1,0);


glEnable(GL_TEXTURE_2D);
//render walls(planes) with texture
glBindTexture(GL_TEXTURE_2D, texture[3]);
glColor3f(1, 1, 1);
glBegin(GL_QUADS);

glTexCoord2f(1.0f, 0.0f); glVertex3f(-320,320,-320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-320,-320,-320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(320,-320,-320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(320,320,-320);

glTexCoord2f(1.0f, 0.0f); glVertex3f(320,320,-320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(320,-320,-320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(320,-320,320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(320,320,320);

glEnd();

//render floor (plane) with colours
glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-800,-320,800);
glTexCoord2f(1.0f, 1.0f); glVertex3f(800,-320,800);
glTexCoord2f(0.0f, 1.0f); glVertex3f(800,-320,-800);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-800,-320,-800);
glEnd();



//render/blend explosions
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, texture[1]);
for(i=0; i<20; i++)
{
if(ExplosionArray._Alpha>=0)
{
glPushMatrix();
ExplosionArray._Alpha-=0.01f;
ExplosionArray._Scale+=0.03f;
glColor4f(1,1,0,ExplosionArray._Alpha);
glScalef(ExplosionArray._Scale,ExplosionArray._Scale,ExplosionArray._Scale);
glTranslatef((float)ExplosionArray._Position.X()/ExplosionArray._Scale, (float)ExplosionArray._Position.Y()/ExplosionArray._Scale, (float)ExplosionArray._Position.Z()/ExplosionArray._Scale);
glCallList(dlist);
glPopMatrix();
}
}

glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);



return TRUE; // Keep Going
}
I made additional changes that helped, but it still has the flashing/flickering problem. This is the new DrawAVI():

void DrawAVI() {
// Grab A Frame From The AVI
GrabAVIFrame(frame);
if(bg) // Is Background Visible?
{
// Reset The Modelview Matrix
glBegin(GL_QUADS);
// Begin Drawing The Background (One Quad)
// Front Face
glTexCoord2f(1.0f, 1.0f); glVertex3f( 11.0f, 8.3f, -20.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-11.0f, 8.3f, -20.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-11.0f, -8.3f, -20.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 11.0f, -8.3f, -20.0f);
glEnd();
// Done Drawing The Background
}
}

I moved the call to DrawAVI() to just after the call to glRotatef(camera_rotation,0,1,0);
The randomness of the flickering was eliminated by removing the call to glTexSubImage2D() at the end of GrabAVIFrame()

void GrabAVIFrame(int frame)
// Grabs A Frame From The Stream
{
static int xScreenLocation = 0;
static int yScreenLocation = 0;
static int xScreenWidth = 0;
static int yScreenHeight = 0;

static int offset = 1;
LPBITMAPINFOHEADER lpbi; // Holds The Bitmap Header Information
lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);
// Grab Data From The AVI Stream
pdata=(char *)lpbi+lpbi->biSize+lpbi->biClrUsed * sizeof(RGBQUAD);
// Pointer To Data Returned By AVIStreamGetFrame

// Convert Data To Requested Bitmap Format
xScreenLocation = 50;
yScreenLocation = 50;
xScreenWidth = width/2;
yScreenHeight = height/2;
DrawDibDraw (hdd, hDC, xScreenLocation, yScreenLocation, width/2, height/2, lpbi, pdata, 0, 0, width, height, 0);

// Swap The Red And Blue Bytes (GL Compatability)
flipIt(data);

// Update The Texture
// glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, 256, 256, GL_RGB, //GL_UNSIGNED_BYTE, data);
}

This topic is closed to new replies.

Advertisement