Original Post
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: 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.
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();
}
}