Results 1 to 2 of 2

Thread: Performance slowing down over time

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    1

    Performance slowing down over time

    Hi,

    I just started to dig into OpenGL on Mac OS X 10.4, using python.

    I recognised a performance loss when an animation is running for several minutes. It's a simple animation: two 3D-objects are rotating around their own axes. The examples come from the nehe tutorials.

    I just added some messages to the terminal window to show the current frame-rate and the seconds needed to display a full rotation of both objects (they rotate with the same speed). The rotation is realised with the GLUT-function "glutTimerFunc()" that is called every 10 milliseconds.

    The rotation interval drops from around 3 seconds at the beginning to 7 seconds after 5 Minutes. The frame-rate is going down as well.

    Is there a special buffer that I have to clear regularly in order to keep a constant performance? Might this be a python problem?

    I'm kind of lost, being new to OpenGL and not being an expert in python either.
    Thanks for any suggestions.

    Hadubard

    P.S.: the source code of the animation in python:
    Code :
    #!/usr/bin/env python
     
    # This statement is required by the build system to query build info
    if __name__ == '__build__':
    	raise Exception
     
    import sys, time
    try:
    	from coordinates import *
    except:
    	print 'ERROR: No coordinates found'
    	print '       Coordinates should be stored in a file called coordinates.py'
    	sys.exit()
     
    try:
      from OpenGL.GLUT import *
      from OpenGL.GL import *
      from OpenGL.GLU import *
    except:
      print '''
    ERROR: PyOpenGL not installed properly.	 
    		'''
     
    params = {
    	'fullscreen':	False,
    	'rotTriangle':	0.0,
    	'rotQuad':		0.0,
    	'speed':		2.0
    }
     
    ellapsedTime =  time.time()
     
    tStart = t0 = time.time()
    frames = 0
     
    def init(): 
    	# set the color used to clear the screen to black
    	glClearColor (0.0, 0.0, 0.0, 0.0)
     
    	# enable smooth shading
    	glShadeModel(GL_SMOOTH)
     
    	# depth buffer
    	glClearDepth(1.0)
    	# glEnable(GL_CULL_FACE)
    	glEnable(GL_DEPTH_TEST)
    	# glDepthMask(GL_TRUE)
    	glDepthFunc(GL_LESS)
     
    	# perspective calculations
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
     
    	return True
     
    def display():
     
    	# Clear The Screen And The Depth Buffer
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     
    	# Reset The Current Modelview Matrix
    	glLoadIdentity()
     
    	# move to the left of the center
    	glTranslatef(-1.5, 0.0, -6.0)
     
    	# rotate around the y axis
    	glRotatef(params['rotTriangle'], 0.0, 1.0, 0.0)
     
    	glEnableClientState(GL_VERTEX_ARRAY)
    	glEnableClientState(GL_COLOR_ARRAY)
     
    	glColorPointer(3, GL_FLOAT, 0, colorsTriangles)
    	glVertexPointer(3, GL_FLOAT, 0, triangles)
    	glDrawArrays(GL_TRIANGLES, 0, 12)
     
    	# Reset The Current Modelview Matrix
    	glLoadIdentity()
     
    	# move to the right of the center
    	glTranslatef(1.5, 0.0, -7.0)
     
    	glRotatef(params['rotQuad'], 1.0, 1.0, 1.0)
     
    	glColorPointer(3, GL_FLOAT, 0, colorsQuads)
    	glVertexPointer(3, GL_FLOAT, 0, quads)
    	glDrawArrays(GL_QUADS, 0, 24)
     
    	glDisableClientState(GL_VERTEX_ARRAY)
    	glDisableClientState(GL_COLOR_ARRAY)
     
    	glColor3f(1.0, 1.0, 1.0)
    	glutWireSphere(0.5, 20, 20)
     
    	glFlush()
     
    	framerate()
     
    	# glutSwapBuffers()
     
    	glutPostRedisplay()
     
    	return True
     
    def reshape(w, h):
     
    	# set up size of the viewport according to the window size
    	glViewport (0, 0, w, h)
     
    	# activate the perpective matrix
    	glMatrixMode (GL_PROJECTION)
     
    	# load identity matrix into active matrix (perspective)
    	glLoadIdentity ()
     
    	# Calculate The Aspect Ratio Of The Window
    	gluPerspective(55.0, w/h, 0.1, 100.0)
     
    	# activate the model matrix
    	glMatrixMode (GL_MODELVIEW)
     
    def keyboard(key, x, y):
    	if key == chr(27):
    		import sys
    		sys.exit(0)
    	elif key == 'f':
    		if not params['fullscreen'] :
    			glutFullScreen()
    			params['fullscreen'] = True
    		else:
    			glutReshapeWindow(640, 480)
    			params['fullscreen'] = False
    	else:
    		return
     
    def rotate():
    	global ellapsedTime
    	params['rotTriangle']+= params['speed']
    	if params['rotTriangle'] == 360:
    		params['rotTriangle'] = 0
    		dt = time.time() - ellapsedTime
    		ellapsedTime = time.time()
    		print "One full rotation in %3.1f seconds" % (dt)
    	params['rotQuad']+= params['speed']
    	if params['rotQuad'] == 360:
    		params['rotQuad'] = 0
     
    	glutPostRedisplay()
     
    def framerate():
    	global t0, frames
     
    	t = time.time()
    	frames += 1
     
    	if t - t0 >= 2.00:
    		seconds = t - t0
    		fps = frames/seconds
    		print "%.0f frames in %3.1f seconds = %6.3f FPS" % (frames,seconds,fps)
    		t0 = t
    		frames = 0
     
    def timer(value):
    	rotate()
    	glutTimerFunc(10, timer, 0)	
     
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
    glutInitWindowSize(640, 480)
    glutInitWindowPosition(100, 100)
    glutCreateWindow('Nice Graphics')
    init()
    glutDisplayFunc(display)
    glutReshapeFunc(reshape)
    glutKeyboardFunc(keyboard)
    glutTimerFunc(0, timer, 0)
     
    glutMainLoop()

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650

    Re: Performance slowing down over time

    Quote Originally Posted by Hadubard
    The rotation interval drops from around 3 seconds at the beginning to 7 seconds after 5 Minutes....Is there a special buffer that I have to clear regularly in order to keep a constant performance? Might this be a python problem?
    Off the cuff guess, yes. Write your program in C++ and compare.
    Shouldn't be hard. The GL/glut calls are basically the same.

Similar Threads

  1. Bad time performance of glGetQueryObjectiv?
    By Dark_Raven in forum OpenGL: GLSL
    Replies: 2
    Last Post: 03-10-2012, 07:12 AM
  2. Replies: 0
    Last Post: 11-26-2010, 11:33 PM
  3. Textures Slowing App
    By Swiftless in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 06-02-2005, 05:15 AM
  4. "frame rate" slowing down with time
    By sek in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 10-01-2003, 01:01 PM
  5. Slowing down a GeForce4!
    By BitBlitter in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 08-13-2002, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean