Advertisement

2D tilemap in OpenGL

Started by May 28, 2003 05:29 AM
2 comments, last by serenity 21 years, 9 months ago
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?
Read this article, it''s just what you want!

http://www.gamedev.net/reference/articles/article934.asp
Advertisement
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.
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/

This topic is closed to new replies.

Advertisement