PDA

View Full Version : How can I get seamless tiles using texture mapping



techno
04-20-2011, 04:01 PM
I have a grid of 8 X 8 points and want to overlay an image on it. I divide the inner grid of 6 X 6 into 4 equal sub-parts of size 3 X 3 each. Let us call this sub-part as tile. The idea is to render these tiles along with their corresponding textures. I divide the grid into tiles because in future I want to test it on a larger grid.
I have done it using following approach but I get seams along the edges. I can't figure out why the seams appear.

First the tiles have corresponding starting co-ords as {(0,0),(0,3),(3,0),(3,3)}.

I have an image of 8 X 8 size which I want to overlay on the super_grid and I store its rgba values in some super_data(8 X 8).

While rendering the tiles I draw them as quads and then overlay the corresponding texture on them. So, if (a,b) are starting co-ords for a particular tile, then I initialize the quad vertices ={
(a-0.5,b-0.5)
(a+3-0.5,b-0.5)
(a+3-0.5,b+3-0.5)
(a-0.5,b+3-0.5)
}
and if xs = 1/(tileWidth+1)=1/(3+1)=1/4 and
ys =1/(tileHeight+1)=1/4, then texture Coordinates are
{
(xs/2,ys/2),
(1-xs/2,ys/2),
(1-xs/2,1-ys/2),
(xs/2,1-ys/2)
}

So, for first tile
quadVertices={(-0.5,-0.5),(3.5,-0.5),(3.5,3.5),(-0.5,3.5)}
and its textureCoords=
{(1/8,1/8),(1-1/8,1/8),(1-1/8,1-1/8),(1/8,1-1/8)}

Before, passing a texture for the tile I initialize the texture : image = new int[tileWidth+2][tileHeight+2] by using the super_data. We take these dimensions because some part of tile texture overlap with the adjacent tiles(that is the reason why we account for this part while calculation of quadVertices).

Finally, use
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tileWidth + 2, tileHeight + 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); to generate the texture.
and use :
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

Everything above works fine, I get a grid with image overlayed on it. However, I get seams at the edges. Please let me know how can I get rid of the seams?

mobeen
04-20-2011, 09:41 PM
Have u tried using nearest filtering?

V-man
04-21-2011, 05:57 AM
http://www.opengl.org/wiki/Common_Mistakes#Texture_edge_color_problem

techno
04-21-2011, 08:17 AM
Yes, I have tried using nearest filtering but it only gives a blurred image with seams persisting as before.