Performance Question

Started by
0 comments, last by Falken42 18 years ago
Hey everyone, I'm making a tile-based game, and I've got some questions regarding the most efficient way to render some stuff. Right now, I'm rendering my tilemap in immediate mode using 2 for loops, the code looks somewhat like this:

glBindTexture(GL_TEXTURE_2D, texture);

for(int x = 0; x < mapwidth; x++)
{
for(int y = 0; y < mapheight; y++)
{
//Texture Coordinates change depending on what image the tile uses
//All the tile images are on one texture that is bound before the loops
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0); glVertex3f(x , y , 0);
glTexCoord2f(1.0,0.0); glVertex3f(x+1 , y , 0);
glTexCoord2f(1.0,1.0); glVertex3f(x+1 , y+1 , 0);
glTexCoord2f(0.0,1.0); glVertex3f(x , y+1 , 0);
glEnd();

}
}


I know that there's a better way to do this, but I don't know how to go about it. Normally I would create a Display List of the tile and then bind the correct texture before rendering the list, but now that I put all my tile textures into one image to reduce the glBindTexture calls, I have to change the texture coordinates to get the right sub texture to work, which takes Display Lists out of the picture (I think). Anyways, does anyone know how I can make this more efficient and less hacked together? Sorry if my post is impossible to understand, let me know if you want me to rephrase stuff.
My Current Project Angels 22 (4E5)
Advertisement
As long as you utilize the same texture across multiple quads, then a single glBegin/glEnd pair is sufficient and will help performance quite a bit. Quads are just that -- four vertices specify a single quad.

If you still need more performance, then I would recommend looking into VBOs. Specify the STATIC_DRAW flag when binding your buffers and the driver will be able to optimize your static geometry for drawing.

This topic is closed to new replies.

Advertisement