So, I have made my tilemap-class, and the code for rendering looks like this:
public void paintMap(GL gl)
{
// loop through all the tiles in the map rendering them
for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
int yoffset = HEIGHT*TILE_SIZE;
Vector3D tilePos = new Vector3D(player.pos.x - x * TILE_SIZE,player.pos.y + y * TILE_SIZE,0);
if (!((Math.abs(tilePos.x) < 420)) || !((Math.abs(-yoffset+tilePos.y) < 300)))
continue;
gl.glColor4d(1 , 1 , 1, 1);
//TODO FIX: 16 SKAL VÆRE DYNAMISK FUNDET......
int tileCol = midlayer[y][x] / 16;
int tileRow = midlayer[y][x] - (16 * tileCol);
gl.glPushMatrix();
gl.glTranslated(0,yoffset ,0);
gl.glTranslated(x * TILE_SIZE, -y * TILE_SIZE, 0);
spriteBuffer.drawFrame(gl, tileCol, tileRow);
gl.glPopMatrix();
}
}
// System.out.println("Passes calculated: "+passesCalc+"\nPasses not calculated: "+passesNotCalc);
}
I profiled it (in netbeans) and I saw that the main problem is in the spriteBuffer.drawFrame(), which kinda sucks. I have one texture file containing all the tiles, and they are saved into separate displaylists in opengl. All rendered to squares. I only render the ones that fit in the screen, so nothing more than like 30x30 or whatever.
Does it matter that I change from one displaylist to another? Is there anything else I can do to upgrade the performance of this code?
I might have to repeat this, it is not a CPU problem, its a GPU problem. The cpu is around 30% with my game at this point. And yes I have a quite lowend graphics card, intel graphics 945GM.