PDA

View Full Version : Performance slowing down over time



Hadubard
07-09-2008, 08:53 AM
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:


#!/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()

Dark Photon
07-09-2008, 06:34 PM
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.