Drawing the TilesOk, now we're ready to finally draw the tiles. I'll go through the code of this tile drawing function step by step.
tile is our place holder variable that will be used in determining if the tile at map[y][x], for example, has an ID# of 0 or 1 when we loop through the map array.
Here we have initialized a doubly-nested loop which will run through our map array, capture each tile's ID#, and then store that ID# in tile, as shown in the next step.
tile now holds the ID# of the tile at location map[y][x].
Here we bind the texture that we need, either texture[0] or texture[1], based on the value of tile, which holds the current tile's ID#.
This is where the actual "tiling" takes place, and a square is rendered at the correct location with the correct texture (texture[tile]). ConclusionThat's it! You now have a simple OpenGL-based tile engine. Here are a couple ideas on how you can optimize it some more yourself.
In conclusion, I hope that a few people now have a better understanding of how to produce 2D/3D tiling with OpenGL. As usual, anyone can email me at either lpsoftware@gdnmail.net or lpsoftware@home.com for remarks, suggestions, or to report any typos/bugs there might be. Visit my website at www.cfxweb.net/lpsoftware This article is © 2000 Martin Estevao. This article may not be re-printed without the author's consent. |