Tiling with SDL/OpenGL
Posted: Wed May 11, 2011 3:36 am
Hello everyone!
I've recently started planning the tiling engine for a game i'm developing with some friends. Let me first give you an overview of where i'm going with this.
The "look and feel" of the terrain is planned to be in a Zelda style, such as in the masterpiece The Minish Cap, but with a couple of added features. First of all, i am thinking of implementing tiles that the player can move both under and over (more on that later). Secondly, i am going with a more "pokemon" kind of overworld, meaning that the map should be loaded on the fly as the player (or rather, the camera) moves around.
So now that you know what i'm looking to implement, let's move on to the details of the current design.
The map will be loaded in "chunks", containing a square of 16*16 or 32*32 tiles (that will depend on the tile size, meaning that if the tiles are 16*16 i'll probably go for 32*32 chunks). Think of a chunk as a small map, since it will function like that. That said, each chunk will contain layers in the following fashion: For the layer the player (or any other object for that matter) is currently on, the tiles on that same layer are the ground and the walls/static objects that have collision. The layers above that are stuff that are drawn above the player, such as roofs, overhanging bridges, treetops etc. Objects can change layers by moving through stairs etc.
This design handles both the features requires, but here now is an issue i'd like some advice on.
The rendering is going to be done in OpenGL mainly, by means of textured quads. These textures will be "constructed" by SDL. Now, something i ruled out early was to render each and every tile as an individual textured quad, due to obvious overhead from binding/unbinding all those textures every frame. The solution i have come to for the time being would be to do the actual tiling of each chunk (only 9 loaded each time btw) with SDL, thus reducing the amount of textures used per frame to 9 + any extra layers that some or all chunks may include. Here is the issue though: animated tiles (water etc). That would require rerendering any chunk textures that contain them + passing them to OpenGL. Of course, that would happen 3-4 times per second tops, so it's still better than doing the same thing every frame, but i'm worried about performance. What i'm looking for is some advice on whether this can be done in a better way, or if there is some way to improve this.
BTW looking forward to AiGD18
I've recently started planning the tiling engine for a game i'm developing with some friends. Let me first give you an overview of where i'm going with this.
The "look and feel" of the terrain is planned to be in a Zelda style, such as in the masterpiece The Minish Cap, but with a couple of added features. First of all, i am thinking of implementing tiles that the player can move both under and over (more on that later). Secondly, i am going with a more "pokemon" kind of overworld, meaning that the map should be loaded on the fly as the player (or rather, the camera) moves around.
So now that you know what i'm looking to implement, let's move on to the details of the current design.
The map will be loaded in "chunks", containing a square of 16*16 or 32*32 tiles (that will depend on the tile size, meaning that if the tiles are 16*16 i'll probably go for 32*32 chunks). Think of a chunk as a small map, since it will function like that. That said, each chunk will contain layers in the following fashion: For the layer the player (or any other object for that matter) is currently on, the tiles on that same layer are the ground and the walls/static objects that have collision. The layers above that are stuff that are drawn above the player, such as roofs, overhanging bridges, treetops etc. Objects can change layers by moving through stairs etc.
This design handles both the features requires, but here now is an issue i'd like some advice on.
The rendering is going to be done in OpenGL mainly, by means of textured quads. These textures will be "constructed" by SDL. Now, something i ruled out early was to render each and every tile as an individual textured quad, due to obvious overhead from binding/unbinding all those textures every frame. The solution i have come to for the time being would be to do the actual tiling of each chunk (only 9 loaded each time btw) with SDL, thus reducing the amount of textures used per frame to 9 + any extra layers that some or all chunks may include. Here is the issue though: animated tiles (water etc). That would require rerendering any chunk textures that contain them + passing them to OpenGL. Of course, that would happen 3-4 times per second tops, so it's still better than doing the same thing every frame, but i'm worried about performance. What i'm looking for is some advice on whether this can be done in a better way, or if there is some way to improve this.
BTW looking forward to AiGD18