PDA

View Full Version : Performance deterioration when drawing 2d bitmaps



dodgyposse
09-13-2000, 12:44 AM
I have a 3d engine going now, and am getting
172 frames per second ( hooray! ).

I wrote some code to draw non transparent
2d pixmaps ( gui dialogs ) over the whole thing and the fps drops to 14 fps.

Surely 2d bitmaps are the most basic function
going. Why am I getting such a performance hit.

The draw method for my bitmap class follows.

void draw( int x,int y,int z )
{
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
gluOrtho2D( 0,640,0,480);
glMatrixMode( GL_MODELVIEW );
glPushMatrix();

glLoadIdentity();
glRasterPos2i( x,
460-y- BitmapInfo.bmiHeader.biHeight>>1) );
if ( !_transparent )
{
glDisable( GL_BLEND);
glDrawPixels( _BitmapInfo.bmiHeader.biWidth,
_BitmapInfo.bmiHeader.biHeight,
GL_BGR_EXT,GL_UNSIGNED_BYTE,_BitmapBits );
}
else
{
glBlendFunc( GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND);
glDrawPixels( _BitmapInfo.bmiHeader.biWidth,
_BitmapInfo.bmiHeader.biHeight,
GL_RGBA,GL_UNSIGNED_BYTE,_BitmapBits );
glDisable( GL_BLEND);
}
glPopMatrix();
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
}

I apologise for the formatting...

Basically, if the bitmap is transparent,
blending is enabled and disable if not transparent.

The biggest hit, is for a 128x64 non transparent bitmap

dd

09-15-2000, 02:11 AM
Your bottleneck is glDrawPixels()
because its not hardware-accelerated
by the most of todays drivers.
Use a textured Quad or 2 triangles instead!