PDA

View Full Version : background drawing slowing down



fortikur
04-22-2004, 08:52 AM
I tried to display a background image 20 times per sec under CBuilder (using timers), but drawing my 400 vertex polygon seems faster than displaying a simple image. I used the following code, which was borrowed from a tutorial:

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glDisable(GL_LIGHTING);

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glEnable(GL_TEXTURE_2D);

// backgr is a 512x512x24 BMP file
glBindTexture(GL_TEXTURE_2D, backgr);

glBegin(GL_QUADS);
glNormal3f(0.0f, 0.0f, 1.0f);
glTexCoord2f(0, 0);
glVertex3f(-1, -1, 1);
glTexCoord2f(0, 1);
glVertex3f(-1, 1, 1);
glTexCoord2f(1, 1);
glVertex3f( 1, 1, 1);
glTexCoord2f(1, 0);
glVertex3f( 1, -1, 1);
glEnd();

glEnable(GL_DEPTH_TEST);

glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glEnable(GL_LIGHTING);

I discovered, that the problem is somehow related to glLoadIdentity(). If I remove the two lines, I see no background - which is normal, but I get 20fps.
Does anyone have an idea, how to draw my background pic faster?

dorbie
04-22-2004, 01:11 PM
No, it's faster because you don't draw anything. The load identity is very inexpensive. My only criticism is that you keep pushing the matrix before you load the identity matrix, this is probably not required, you only need to push the matrix stack if you want to restore what's on it back later. The last thing you would want to do is push before an identity load unless you were trying to return the stack to it's previous state after drawing your background. This will not be slowing you down either.

Displaying your background image takes a lot of work to texture all the pixels with your image. You could make this faster by disablind depth tests & writes and by changing your texture filter, perhaps to GL_NEAREST and by changing the internal format of the texture and using a GL_REPLACE texture environment instead of GL_MODULATE, but quality will be affected by some of these.

If you're slower than 20fps you may not have a hardware accelerated OpenGL context. Upgrade your drivers and make sure your pixel format descriptor is accelerated, and perhaps upgrade your graphics card if you still have problems.

fortikur
04-22-2004, 10:22 PM
Damn! I found the problem. You were right about the drivers. I've never thought WinXP would detect my Asus Geforce 6800 as a Nvidia Geforce DDR.
I downloaded the drivers and voilá! It runs fine.
I just switched to XP from 98 and as XP recognized my graphics card, I didn't care about looking after its type stored in the driver settings.
Thank you