Jump to content
  • Advertisement
Sign in to follow this  
Sir Sapo

Performance Question

This topic is 4493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!