Jump to content
  • Advertisement
Sign in to follow this  
LordAsm

OpenGL Approaches on texturing tiles

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to know the best approach to make a tile-based isomeric map using OpenGl. I made a bunch of quads, and used a heightmap bitmap to make elevation, and applied one texture. But i want to have mutiple textures and also blends of textures in my map. What approach I should take to achieve this? Is it best to render each quad of the map isolated within a glBegin() and GlEnd() and apply a texture individually or it is best to load a gigantic texture of the entire map and make all quads between one glBegin() - glEnd() clause? Thanks! LordAsm

Share this post


Link to post
Share on other sites
Advertisement
Out of the two examples you listed, it would be better to do the 2nd. This is because glBegin()/glEnd() is the slowest method of drawing.

Binding textures is also quite costly. The less frequently you change textures the better.

The BEST approach would be with display lists or vertex arrays. But since this is an isometric game you can probably afford the speed hit of just using glBegin()/glEnd().

Share this post


Link to post
Share on other sites
Okay, and let's ask another thing then.

Lets suppose I have a small map,

1112333
1122333
1123333
1123333
1122333
1112333

where 1 is mud, 3 is sand and 2 is the transition of them

How can I, in OpenGL, make this transition efficiently? In other words, how in a single quad I can make a texture blend?

Ty!
-LordAsm-

Share this post


Link to post
Share on other sites
Using 3 different tiles each in their own file:

int[][] map = initMap(); // Assume this creates the map you described
int[] tileKey = {0, 1, 2}; // Mud, Transition, Sand

void drawMap(){
for(int i = 0; i < textureNames.length; i++){
glBindTexture(GL_TEXTURE_2D, Engine.getTextureId(tileKey));
glBegin();
for(int x = 0; x < mapWidth; x++){
for(int y = 0; y < mapHeight; y++){
if(map[x][y] == tileKey)
drawQuad(x * tileWidth, y * tileHeight, tileWidth, tileHeight); // drawQuad(int offsetX, int offsetY, quadWidth, quadHeight);
}
}
glEnd();
}
}







The above is just one example. A better approach is to have all the tiles in one texture:

tiles.png (512px X 512px)
_ _ _ _ _ _
| | | GRS = Grass tile
| MUD | GRS | TRNS = Transition tile
|_____|_____| SAND = Sand tile
| | | MUD = Mud tile
|TRNS |SAND |
|_ _ _|_ _ _|

Then, the process goes:
1) Bind tiles.png texture.
2) glBegin();
3) Draw map
A) Loop through map[][]
B) offset the quad's texture coordinates depending on which tile needs to be drawn.
ex)if(map[x][y] == "sand"), change texture coords to to draw the lower right part of the tiles.png texture
4) glEnd();

Share this post


Link to post
Share on other sites
okay, let's take then your example....

_ _ _ _ _ _
| | | GRS = Grass tile
| MUD | GRS | TRNS = Transition tile
|_____|_____| SAND = Sand tile
| | | MUD = Mud tile
|TRNS |SAND |
|_ _ _|_ _ _|

In this case I would only have a transition of mud/sand/grass in the upper-right corner, if I was to make all transitions in all possible directions with at least 10 types of terrain (mud, sand, grass, rock, lava, burn ground, etc) it woudn't be a LOT of textures? If would not take too much memory to load and then space in disk!?

Isn't a way to blend textures as the same way you blend colors in a quad when you use glColor3f(); ??? This would keep me away from loading a lot of textures or a super-big texture, and would make programatically-correct blending? I read about something concerning pixel shaders or vertex shaders, don't remember...

Something like that:

RED GREEN
_ _ _ _ _ _ _
| |
| |
| |
| |
| |
| |
|_ _ _ _ _ _ _|
BLUE WHITE

To be like:

GRASS MUD
_ _ _ _ _ _ _
| |
| |
| |
| |
| |
| |
|_ _ _ _ _ _ _|
SNOW SNOW

And i'll blend them together programatically.... There's any approach that comes to what I thought, or a way I didn't need to draw a lot of textures and read them!?

Ty!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!