[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pygame] OpenGL and blitting
What would be the preferred method of blitting pygame surfaces to an
opengl screen? I couldn't get OPENGLBLIT to work, so I ended up making the
following function:
def gl_blit(surface, (x,y)):
sx,sy = surface.get_size()
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glRasterPos2f(x,y)
bytes = pygame.image.tostring(surface,"RGBX",1)
glDrawPixels(sx,sy,GL_RGBA,GL_UNSIGNED_BYTE,bytes)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
It works, but it is REALLY slow (relatively speaking), even with small
surfaces. Most of the time is spent in glDrawPixels. Commenting it out
makes things fast again. I timed it, and glDrawPixels seems to take about
1.4 ms. Since my game's whole main loop (draw the 3D scene, read user
input, calculate movement etc.) takes about 1.6 ms (without glDrawPixels),
it effectively halves my frames per second.
Any suggestions?
--
Sami Hangaslammi
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org