   PyOpenGL is suspiciously slow
  I downloaded the Python port of the NeHe OpenGL tutorials (linked from this page) as a set of examples to familiarize myself with OpenGL in Python so I could adapt my purely-SDL game to use OpenGL. My goal is to get increased drawing performance, since right now, much of my time is being spent in the "fill" and "blit" methods of pygame.Surface objects. So I whipped up this simple program based on lesson #6 (which draws a spinning, textured cube):import cProfileimport OpenGL.GL as GLimport OpenGL.GLU as GLUimport pygame, pygame.localsimport timeprint "Start"pygame.init()screen = pygame.display.set_mode((800, 600),    pygame.locals.OPENGL | pygame.locals.DOUBLEBUF)GL.glViewport(0, 0, 800, 600)GL.glMatrixMode(GL.GL_PROJECTION)GL.glLoadIdentity()GLU.gluPerspective(45, 800.0/600, .1, 100)GL.glMatrixMode(GL.GL_MODELVIEW)GL.glLoadIdentity()print "View set"GL.glEnable(GL.GL_TEXTURE_2D)GL.glEnable(GL.GL_BLEND)GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)surfaces = [pygame.image.load("/Users/chriswei/proj/games/jetblade/data/sprites/terrain/jungle/grass/blocks/allway/%d.png" % x) for x in [1, 2]]textureData = [pygame.image.tostring(surfaces, "RGBX", 1) for i in range(2)]for i in xrange(2):    GL.glBindTexture(GL.GL_TEXTURE_2D, i)    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, surfaces.get_width(), surfaces.get_height(), 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, textureData)    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST)    GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST)GL.glShadeModel(GL.GL_SMOOTH)GL.glClearColor(0, 0, 0, 0)GL.glClearDepth(1)GL.glEnable(GL.GL_DEPTH_TEST)GL.glDepthFunc(GL.GL_LEQUAL)GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST)print "Draw options set"def loop():    prevTs = int(time.time())    start = time.time()    frame = 0    cam = -20    dcam = .5    while 1:   frame += 1   event = pygame.event.poll()   if event.type == pygame.locals.KEYDOWN and event.key == pygame.locals.K_ESCAPE:  print "FPS: %f" % (float(frame) / (time.time() - start))  break GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)   GL.glLoadIdentity()   GL.glTranslatef(0, 0, cam)   if int(time.time()) != prevTs:  prevTs = int(time.time())  GL.glBindTexture(GL.GL_TEXTURE_2D, prevTs % 2)   GL.glBegin(GL.GL_QUADS)   size = -.5   blocks = 20   for x in xrange(-blocks/2, blocks/2):  for y in xrange(-blocks/2, blocks/2): GL.glTexCoord2f(0, 0) GL.glVertex3f(size * x, size * y, 0) GL.glTexCoord2f(1, 0) GL.glVertex3f(size * x + 1, size * y, 0) GL.glTexCoord2f(1, 1) GL.glVertex3f(size * x + 1, size * y + 1, 0) GL.glTexCoord2f(0, 1) GL.glVertex3f(size * x, size * y + 1, 0)   GL.glEnd()   cam += dcam   if (cam > -10 and dcam > 0) or (cam < -30 and dcam < 0):  dcam *= -1   pygame.display.flip()cProfile.run("loop()", "profiling.txt")The two textures loaded are just 100x100 PNG files: 1 2. Drawing 400 tiles like this, I'm getting 15FPS, which just seems absurdly low. Profiling doesn't tell me where all of my time is going, but it does tell me that I'm making 583000 calls each to glCheckError and nullGetError. This implies to me that I've done something screwy. However, I see a similar number of errors when I run the lesson 6 code under cProfile.Anyone have any ideas what is going wrong here? I would expect OpenGL to be significantly more performant than SDL here. 400 textured quads does not sound like a lot to me.   
  Hmm 15 does sound pretty slow. You're using immediate mode rendering which is pretty old and sucky (glBegin/glEnd, look into VBO's instead), but I wouldn't expect it to be that slow. Maybe change your loop to one tile from 400 and see if that helps, maybe something else in your program is slowing you down. One thing you can check is glGetString(GL_VENDOR) to check that your drivers are installed correctly. It's possible that you're defaulting somehow to microsoft software implementation, which is going to be pretty slow. Should say nvidia / ati depending on your hardware.I've got no idea why its making so many calls go glGetError, that could hurt performace, although I don't know how long you profiled for so the raw call count is kind of meaningless.;  If I render 100 tiles then I get 60FPS; basically, my framerate scales linearly with the number of tiles I'm drawing. So it's definitely the drawing that's slowing me down. Vendor shows as ATI Technologies Inc. My graphics card is not exactly new but it's fully capable of playing games like Portal and Torchlight, so this shouldn't give it any trouble. I'll look into VBOs when I have enough time to do more than minor tweaks while I eat breakfast. Thanks for the advice.   ;  You can try VBO but I'm not getting a great feeling that its going to help you, you shouldn't be nearly that slow for just drawing some quads. Maybe its something in the python environment, I don't know.   