here in a nutshell is the core code…
(note, even faking it, with 2 static images flipping back and forth, it will freeze after 5 seconds)
void GLRender(void)
{
RenderVideoToTexture(pathToFile); // this calls CMoviePlayer::DisplayFrame below
}
void CMoviePlayer::DisplayFrame(AVFrame *pFrame, int width, int height, float quadWidth, float quadHeight)
{
glBindTexture(GL_TEXTURE_2D, textureID); //A texture you have already created with glTexImage2D
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)pFrame->data[0]);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f,1.0f); glVertex3f (-quadWidth, -quadHeight, 0.0);
glTexCoord2f(1.0f,1.0f); glVertex3f ( quadWidth, -quadHeight, 0.0);
glTexCoord2f(1.0f,0.0f); glVertex3f ( quadWidth, quadHeight, 0.0);
glTexCoord2f(0.0f,0.0f); glVertex3f (-quadWidth, quadHeight, 0.0);
glEnd();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1024,768);
int m_window = glutCreateWindow("2D Image Texture Test");
//glutKeyboardFunc(&processNormalKeys);
//glutEnterGameMode(); //set glut to fullscreen using the
glutDisplayFunc(&GLRender);
glutMainLoop();
return 0;
}
What I’m doing:
-
I decode frames of video
-
I call DisplayFrame
-
It works fine, but after 5 seconds the image freezes.
The app does not crash, if I break, the display function does keep getting called with new frames.
I tried a test where I faked it.
I displayed 2 frames from 2 bmp files. I display each for 1 second then change and display the 2nd image, back and forth.
Even this faked version freezes after 5 seconds…
Note: My GLRender function is not a true render function, is this part of the problem? It really just calls my functions which deals with all the rendering.
Also, freaky enough, I discovered by accident, that if I start the app, and click on another window (that is I remove the focus from the opengl app/window), it works fine 100% of the time.