PDA

View Full Version : Causes of flickering/disappearing objects



Ross Oliver
04-11-2010, 05:06 AM
Hello,

I have a strange problem that appears when I render several GLU objects (cylinders/spheres/disks mainly) to a framebuffer object and then render a quad face of the resulting texture to a GLUT window. The behaviour I get is a flickering - in that entire cylinders or disks will disappear for a few frames then reappear and then disappear again etc. What makes this even weirder is that sometimes when I run my application everything displays perfectly, with no flickering at all.

I've checked everything obvious thing I can think of including; clearing depth buffers, flushing the opengl pipeline (tried both glFlush and glFinish - in the framebuffer rendering segments and the main display method), calling glutSwapBuffers and double-buffering is enabled in GLUT. I just can't seem to stop this odd behaviour.

If anyone could suggest other causes for the symptoms I mentioned I would greatly appreciate it.

Thanks for your time,

-Ross

strattonbrazil
04-11-2010, 09:09 AM
Can you post your code of where you setup your quadrics? Like instantiate them and minimal display code?

Ross Oliver
04-11-2010, 10:18 AM
It's all quite integrated into a large application, but here is a bit of code:



int main( int argc, char *argv[] )
{
pthread_t sm_thread;
int sm_rc;

glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize( CM_WIDTH, CM_HEIGHT );
glutInitWindowPosition( 100, 100 );
glutCreateWindow( "Window" );

glInit();

// Additional thread to do some non-opengl stuff.
sm_rc = pthread_create( &sm_thread, NULL, smMain, NULL );

if( sm_rc )
{
printf( "main.c main: %d\n", sm_rc );
exit( -1 );
}

glutDisplayFunc( glDisplay );
glutReshapeFunc( glReshape );
glutIdleFunc( glIdle );

glutMainLoop();

return 0;
}

GLvoid glInit( GLvoid )
{
// initialise quadrics etc (depth test and what not enabled too)
disk_quadric = gluNewQuadric();
cylinder_quadric = gluNewQuadric();
sphere_quadric = gluNewQuadric();

// set up framebuffer
...
// set up display lists
...

... etc ...
}

GLvoid glDisplay( GLvoid )
{
if( stuff_to_render )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );

cmRenderToFrameBuffer();

glPushMatrix();
{
... then render contents of texture bound to framebuffer
(via display list)...
}
glPopMatrix();

glutSwapBuffers();
}
}

GLvoid glReshape( GLint width, GLint height )
{
GLfloat w, h;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

w = ( ( GLfloat ) width / ( GLfloat ) height );
h = ( ( GLfloat ) height / ( GLfloat ) width );

glFrustum( -w, w, -h, h, 5.0f, 60.0f );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -10.0f );
}

GLvoid glIdle( GLvoid )
{
glutPostRedisplay();
}

GLvoid cmRenderToFrameBuffer()
{
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb );

glClear( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );

glPushMatrix();
{
glCallList( cylinder );

.. etc ..
}
glPopMatrix();

glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );
}

GLvoid cmCylinder( GLvoid )
{
glRotated( 90.0, 1.0, 0.0, 0.0 );
gluCylinder( cylinder_quadric, 0.2, 0.2, 0.15, 20, 1 );

gluDisk( disk_quadric, 0.0, 0.2, 25, 5 );
glTranslatef( 0.0f, 0.0f, 0.15f );
gluDisk( disk_quadric, 0.0, 0.2, 25, 5 );
}

GLvoid cmSphere( GLvoid )
{
gluSphere( sphere_quadric, 0.2, 20, 20 );
}

GLvoid cmQuadFace( GLvoid )
{
glPushMatrix();
{
glBegin( GL_QUADS );
{
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0, 0.0f, 0.0f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( 0.0f, 1.0f, 0.0f );
}
glEnd();
}
glPopMatrix();
}


Thanks again,

-Ross

strattonbrazil
04-12-2010, 10:26 AM
I see you're not making any viewport calls. Is your FBO the same size as your window?

Ross Oliver
04-12-2010, 01:22 PM
I just assumed the framebuffer was initialised as having the same size as the window - is this not the case? I'm afraid I'm not familiar with the viewport calls - do they set the clipping areas etc? Would they be needed for just the window or the framebuffers as well?

Many thanks,

-Ross

Ross Oliver
04-13-2010, 08:56 AM
I've added glPushAttrib/glPopAttrib and glViewPort calls in my reshape OpenGL method and any time I render to a frame buffer - this doesn't appear to have resolved the issue unfortunately though...

-Ross