# Texturing problem - weird swap

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

## Recommended Posts

Image shows 9 slices of mesh when i try to texture each segment and i hit the boundary (x = dimension) or y = dimension

i get somehow a swap, you can clearly see this on the top right slice when at the bottom of it you see blue line of water (between land)

heres a sample of a texture (its not a texture form the image) but this faulty texturing occurs on every mesh (whatever texture i use) (i just cant remember where i was to obtain the texture in topright segment-)

as you can see theres no blue line at the bottom (dont mind for left right sides line its the same algorithm for that)

now the texture has a dimension 2x larger than a mesh (mesh has 120x120 pixels, texture has 240x240)

no when i create a mesh i do something like this:

for y to 120

for x to 120

{

create_4_vertices_from_the_mesh_heightmap (each (x y) (x+1,y), (x+1 y+1), (x, y+1) )

} so i basically make 4 verts out of every pixel

then i texture it by



float fdim = 120.0f;
float fpy;
float fpx;
for (y=0; y < 120; y++)
for (x=0; x < 120; x++)
{

fpx = float(x);
fpy = float(y);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint(fpx/fdim,              (fdim-fpy) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint((fpx+1.0f) / fdim,     (fdim-fpy) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint((fpx+1.0f) / fdim,     (fdim-(fpy+1.0f)) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint(fpx / fdim,            (fdim-(fpy+1.0f)) / fdim);
}


Edited by WiredCat

##### Share on other sites

I am sorry, I know this isn't relevant, but it is necessary...

Edited by dsm1891

##### Share on other sites

It looks like you are either using repeating texture coordinates (with tri/bilinear interpolation), or you are simply reading outside your own texture (also because of interpolation).

Some explanations:

http://hacksoflife.blogspot.no/2009/12/texture-coordinate-system-for-opengl.html

http://jfix.by/2013/02/23/opengl-filters/

And a zillion others :)

The "problem" itself is just a result of how linear interpolation samples nearby pixels.

Solutions include, but not limited to:

1. Using clamping (GL_CLAMP_TO_EDGE)

2. Have your texture coordinates well inside a sub-image on a texture atlas (watch out for mipmapping issues)

3. Use texture 2D arrays (need to be square sized)

4. Use shader magic to avoid sampling outside of image, or centroid sampling (centroid not recommended)

##### Share on other sites

indeed thanks for the info i solved it you pointed me to use gl_clamp_to_edge and that was the milestone in the research i just looked at

https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexParameter.xml

all i had to do was:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013754
×