Hello,
I recently started an openGL 2d game and I’m in the process of optimizing.
It’s a really simple engine, the only thing it has to do is draw transparent images at a certain x and y.
While I got it reasonably fast I want it to draw up to 5000 textures per frame at 60 fps. It can do this already but only on modern hardware.
I might want to add more complexity later and I’m afraid the graphics engine just can’t keep up.
After doing some measurements I noticed it’s spending 7500 microseconds on drawing a frame and 1000 microseconds on all the other code.
I’d like some help on trying to improve it’s speed.
This is the code of my engine.
Initialization:
width=600;
height=600;
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Texture Loading:
glGenTextures(textureids);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, imageByteBuffer);
Actually drawing images, this part gets called 5000 times per frame.
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, gltexid);
glTranslatef(x, y, 0);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, heightratio);
glVertex2f(0, imageheight);
glTexCoord2f(widthratio, heightratio);
glVertex2f(imagewidth, imageheight);
glTexCoord2f(widthratio, 0);
glVertex2f(imagewidth, 0);
}
glEnd();
glPopMatrix();
widthratio = imagewidth/texturewidth
heightratio = imagewidth/texturewidth
Now, like I said. This code is not fast enough. Does anyone know how I could speed this code up?
I’ve taken a look at display lists but I do not know if they would actually improve my performance.
I’d really appreciate any help anyone could give.
The game is written in java using lwjgl to bind to OpenGL.
The OpenGL version used is 1.1. Would switching to a different version increase speed?