//------------------------------------------------------------------------ // Demonstrate memory leak for i965 // Only specific combination of different primitive types with some regular // changes of attributes shows the memory leak //------------------------------------------------------------------------ #include #include #include #include #include // sin, cos #define MY_PI 3.1415 int loop = 1; // Anzahl Bilder zum Zeichnen //---------------------------------------------------------------------------- void init() { GLfloat lgt_ambient[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat lgt_diffuse[4] = { 0.8f, 0.8f, 0.8f, 1.0f }; glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lgt_ambient ); glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, 0 ); glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, 0 ); glLightfv( GL_LIGHT0, GL_DIFFUSE , lgt_diffuse ); glLightfv( GL_LIGHT0, GL_SPECULAR, lgt_diffuse ); glLightfv( GL_LIGHT0, GL_AMBIENT, lgt_ambient ); glClearColor( 0.1, 0.6, 0.1, 0.0 ); glEnable( GL_COLOR_MATERIAL ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); } //---------------------------------------------------------------------------- void display() { for( int id = 0; id < loop; ) { // each new loop eats memory while (loop == 1) { // when loop == 1 do an endless loop id++; if (((id % 100) == 0 ) && ( loop > 1)) { double q = 100.0 * (double)id / double(loop); printf(" %5d (%2.0lf %%)\n", id, q); } else { printf(" %5d \n", id); } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix(); double rot = 0.9 * id; double sca = 0.5; glRotatef( rot, 20, rot, 1.0 ); glScalef( sca, sca, sca ); const float r = 0.1f; glPushAttrib( GL_ENABLE_BIT | GL_LIGHTING_BIT ); glDisable( GL_CULL_FACE ); glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, 1 ); // omit this to have no more memory leak glBegin( GL_QUADS ); glNormal3f( +0.0f, +0.0f, +1.0f ); glVertex3f( +r, +0.0f, +0.0f ); glVertex3f( +0.0f, +r, +0.0f ); glVertex3f( -r, +0.0f, +0.0f ); glVertex3f( +0.0f, -r, +0.0f ); glNormal3f( +0.0f, +1.0f, +0.0f ); glVertex3f( +r, +0.0f, +0.0f ); glVertex3f( +0.0f, +0.0f, +r ); glVertex3f( -r, +0.0f, +0.0f ); glVertex3f( +0.0f, +0.0f, -r ); glEnd(); glPopAttrib(); glPushAttrib( GL_ENABLE_BIT ); glDisable( GL_LIGHTING ); // omit this to have no more memory leak glBegin( GL_LINES ); glVertex3d( 0.0, 0.0, 1.0 ); glVertex3d( 0.0, 0.0, 0.0 ); glEnd(); glPopAttrib(); const int res = 8; const double delta = 2.0 * MY_PI / res; glPushAttrib( GL_ENABLE_BIT | GL_LIGHTING_BIT ); glDisable( GL_CULL_FACE ); glBegin( GL_TRIANGLE_FAN ); glNormal3f( 0.0f, 0.0f, -1.0f ); glVertex3d( 0.0, 0.0, 0.0 ); for( int tri = res; tri >= 0; tri-- ) { double angle = tri * delta; double ca = cos(angle); double sa = sin(angle); glVertex3d( ca, sa, 0.0 ); } glEnd(); glPopAttrib(); glPopMatrix(); float z = 1.0; glBegin( GL_LINE_LOOP ); glVertex3f( 0.0f, 0.0f, z ); glVertex3f( 1.0f, 0.0f, z ); glVertex3f( 1.0f, 1.0f, z ); glVertex3f( 0.0f, 1.0f, z ); glEnd(); glutSwapBuffers(); } } exit(0); } //---------------------------------------------------------------------------- void reshape( int w, int h ) { const float halfwidth = 0.6; glViewport( 0, 0, (GLsizei) w, (GLsizei) h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( -halfwidth, halfwidth, -halfwidth, halfwidth, -10.0, 10.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); } //---------------------------------------------------------------------------- int main( int argc, char * argv[] ) { glutInit( &argc, argv ); if( argc == 2 ) { int id = 1; loop = atoi( argv[id++] ); printf("draw %d pictures\n", loop ); } else { loop = 1; } glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize( 600, 400 ); glutInitWindowPosition( 0, 100 ); glutCreateWindow( argv[0] ); init(); glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutMainLoop(); return 0; }