I just implemented basic opengl rendering into my pygame application thinking hardware acceleration would make the program run faster. It is much, much slower instead.
Looks like the problem is the drawing function.
Here is my opengl drawing function
def draw(self, screen):
rect = self.texture.imagerect.copy()
rect.x += self.xoffset
rect.y += self.yoffset
halfWidth = self.getWidth()/2
halfHeight = self.getHeight()/2
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, self.texture.getTexID())
self.color.setGLColor()
glPushMatrix()
glTranslatef(rect.x,rect.y,0)
glRotatef(self.angle, 0, 0, 1);
glBegin(GL_QUADS)
glTexCoord2d(0,0)
glVertex2f(-halfWidth + self.pivot.x, -halfHeight + self.pivot.y)
glTexCoord2d(0,1)
glVertex2f(-halfWidth + self.pivot.x,-halfHeight + self.getHeight() + self.pivot.y)
glTexCoord2d(1,1)
glVertex2f(-halfWidth + self.getWidth() + self.pivot.x,-halfHeight + self.getHeight() + self.pivot.y)
glTexCoord2d(1,0)
glVertex2f(-halfWidth + self.getWidth() + self.pivot.x,-halfHeight + self.pivot.y)
glEnd()
glPopMatrix()
what my profiler gives for the draw function
ncalls tottime percall cumtime percall filename:lineno(function)
312792 20.395 0.000 34.637 0.000 image.py:61(draw)
the rest of my profiler text: (expires in 1 month)
my sourcecode
https://bitbucket.org/claysmithr/warbots/src
Note: when i set it to not draw any tiles i get 60 fps! I also get 20 fps if i limit to only draw tiles that appear on the screen, but this is still much slower than blitting
Number of tiles i'm trying to draw (64x64): 15,625
Is there any way to test if I am really hardware accelerated?
Should I just go back to blitting?
edit: Does blitting automatically not draw tiles that are not on the screen? that could be the reason why opengl is being so slow!