Archived

This topic is now archived and is closed to further replies.

serenity

2D tilemap in OpenGL

Recommended Posts

Hi guys. I''ve been porting a 2d tile world game across to Open GL, and things are going pretty nicely. I display the tiles as a set of quads in orthogonal mode to avoid any depth concerns, and it works nicely. But I''d love it if I could blend between my tiles (say grass to forest, for instance) automatically without having to create a million edge tiles and so on. Is this logical and easy to do in OpenGL? Has anyone else been doing 2d tile maps, and if so, what methods do you use for displaying your tiles?

Share this post


Link to post
Share on other sites
Thanks for the link, and that is almost what I am doing at present.
I was hoping for a nice OpenGL hardware accelerated method that would automatically blend between two base tiles. Of course I wouldn''t get nice corners, and so on, but if possible it would allow for automated blending between two different types of base tyles without having to specifically handle the creation of corner graphics myself.

Share this post


Link to post
Share on other sites
if I get you right..

you will have to draw the base (bottom) tile first with no blending..

and then draw the second tile

after using the following..

glColor4f(0.5f,0.5f,0.5f,0.5f);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); // Enable Blending

that will blend in top tile to the bottom tile at 50% (it also allows you to fade in a tile (or fade it out)

you will probably have the change you alpha matching function value so it works with the adjusted alpha of the second tile.. Ie. most people use glAlphaFunc(GL_GREATER,0.9f) but if you want to draw the second tile (at .5f alpha) then set your alpha funct to .4

hope that helps

http://members.iinet.net.au/~cleathley/

Share this post


Link to post
Share on other sites