nhartung
06-16-2010, 10:45 AM
I'm currently working on a 2D tiling map editor. The map is made up of several floors which are made of several layers which are made up of several tiles. I have just finished writing the code to draw my map and I noticed that the program was running very slowly. The window would take a second to react when i tried to move it and when I resize the window it takes awhile for my reshape function to redraw everything properly. I went back and looked at my code and realized that even my basic example map with a size of 100x100 tiles was actually very large considering it was drawing all of the floors and layers for each floor on every iteration. My first run was actually drawing around 1 million quads every iteration. So I decided to tone down the amount of floors and layers in my map but it was still running slowly. I just got done implementing it with vertex arrays because I thought that it may increase the speed which it didn't. My question is there anyway to speed up the way I draw my quads? Or do I just need to find a way to not redraw so many? Here is the code im currently using to draw my map. This is the lowest level of abstration so this code just draws a single tile but this is the code that it being looped through for each tile.
void tile::draw(unsigned int tileset[])
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, tileset[textureID]);
glPushMatrix();
glTranslatef(xPos, yPos, 0);
glTexCoordPointer(2, GL_FLOAT, 0, Colors);
glVertexPointer(2, GL_FLOAT, 0, Vertices);
glDrawArrays(GL_QUADS, 0, 4);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}
void tile::draw(unsigned int tileset[])
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, tileset[textureID]);
glPushMatrix();
glTranslatef(xPos, yPos, 0);
glTexCoordPointer(2, GL_FLOAT, 0, Colors);
glVertexPointer(2, GL_FLOAT, 0, Vertices);
glDrawArrays(GL_QUADS, 0, 4);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}