View Full Version : Tiling multiple textures

03-28-2010, 01:53 PM
As someone who is just getting his feet wet in parts of OpenGL that don't lie between glBegin() and glEnd(), I'm curious what the most efficient method of rendering a square grid of tiles would be. Currently, I figure out which tiles are actually visible on screen, then loop through them all, binding the appropriate texture, applying a translation, then calling glDrawArrays(). This, as is becoming incredibly obvious to me, is very slow.

I've seen that I should probably be dynamically building a texture atlas instead of rebinding textures all the time, and then using texcoords to pick my texture.

I'm curious what method I should use to render only tiles that are visible on-screen at any given time. If I was always rendering the entire thing, I'd just make a VBO with every possible vertex and another buffer with the proper indices, and just render that each frame. Would it be reasonably efficient to deal with a moving camera by still making a VBO with every possible vertex and then a changing index buffer as the camera moves around? Or am I approaching this the wrong way? Would it be reasonable to have a texcoord buffer changing each frame, or would it be smarter (if slightly more of a memory hog) to keep the texcoords for the entire world in memory along with the vertices? (Also, are all these options possible? I haven't spent enough time perusing the buffer objects documentation to know.)

03-28-2010, 05:22 PM
It depends a little on how many tiles we are dealing with, but generally speaking just stuffing it all in a big VBO works just fine, your gpu will cull the polygons for you so don't worry.
If your doing an obscene amount if tiles (more than 40000) then you could go ahead and split the grid in smaller grids and apply you culling algorithm on those.

03-28-2010, 08:36 PM
Okay, so basically, your recommendation is to avoid changing VBOs if at all possible? That makes sense to me. Thanks.