Original Post
Hi all, I'm not sure what exactly I'm doing wrong. I'm trying to make a 2d engine in opengl right now. My video card is kinda crappy (a pci gforce fx 5200), but still, I don't think it should be going this slow. Bascially, I'm just rendering the same image and covering the screen with it, and to try and stress it, do that several times per frame. As it stands now, I can only layer on 1-10 times depending on the sprite size before the program slows down. If it's a big image, I can layer about 10 times, and if it's a small image (I went down to 5x5), even 1 full layer slows down a lot. Per second wise, I get about 30k pictures per second for the big pictures (64x64) and about 200k pictures per second for the small pictures (10x10 and 5x5). I've tried display lists, I've tried to limit the number of calls to bind texture, and they make literally no difference on my fps. Here is my code to draw a sprite And here is my code to layer them on the screen (just quick test code, but it might be important). Any help would be appreciated.
void bstSprite::drawSprite(float x, float y, float layer,
float scale_x, float scale_y, float turnDegree,
float *hotspot_x, float *hotspot_y,
rgbaIntensity *rgba, txtCoords *tc) {
//Get our draw coordinates
float drawWidth, drawHeight;
float left, top, right, bottom;
if(tc != NULL) {
//If we have texture coordinates, get from there
drawWidth = (tc->right-tc->left)*trueWidth;
drawHeight = (tc->bottom-tc->top)*trueHeight;
left = tc->left;
top = tc->top;
right = tc->right;
bottom = tc->bottom;
} else {
//Otherwise assume they want the full image.
txtCoords *tcFull = makeTxtCoords(0, 0, width-1, height-1);
drawWidth=width;
drawHeight=height;
left = tcFull->left;
top = tcFull->top;
right = tcFull->right;
bottom = tcFull->bottom;
delete tcFull;
}
//Save our current state
glPushMatrix();
//Set color, if passed
if(rgba != NULL) {
glColor4f(rgba->redI, rgba->greenI, rgba->blueI, rgba->alphaI);
}
//Move to position
glTranslatef(x, y, layer);
//Translate to the center of the picture
if(hotspot_x != NULL && hotspot_y != NULL) {
glTranslatef((*hotspot_x)*scale_x, (*hotspot_y)*scale_y, 0);
} else {
glTranslatef(drawWidth/2*scale_x, drawHeight/2*scale_y, 0);
}
//Rotate
glRotatef(turnDegree, 0.0f, 0.0f, 1.0f);
//Go up to our new upperleft corner so that we can draw
if(hotspot_x != NULL && hotspot_y != NULL) {
glTranslatef(-(*hotspot_x)*scale_x, -(*hotspot_y)*scale_y, 0);
} else {
glTranslatef(-drawWidth/2*scale_x, -drawHeight/2*scale_y, 0);
}
//Prepare the texture
glBindTexture(GL_TEXTURE_2D, texSprite);
//Now draw!!1
glBegin(GL_QUADS);
glTexCoord2f(left, top);
glVertex2d(0, 0);
glTexCoord2f(left, bottom);
glVertex2d(0, drawHeight * scale_y);
glTexCoord2f(right, bottom);
glVertex2d(drawWidth * scale_x, drawHeight * scale_y);
glTexCoord2f(right, top);
glVertex2d(drawWidth * scale_x, 0);
glEnd();
//Go back to our original state
glPopMatrix();
}
for(r = 0; r < 10; r++) {
for(x = 0; x < 640; x = x+s->getWidth()) {
for(y = 0; y < 480; y = y+s->getHeight()) {
s->drawSprite(x,y,1,1,1,a,NULL,NULL,&rgbaWhite,NULL);
}
}
}