I am drawing a 2D tiled map
but it have a gap between tiles when zooming in (scale bigger)
zoom out have not problem
I found many thread said that to change the texture filter to GL_NEAREST will solve the issue, it solved in my case,
but i still prefer to use GL_LINEAR because it create better result.
is there any way to fix those gaps but using GL_LINEAR filtering?
thank you very much
The linear filter is sampling outside the range of the tile at the border. What texture wrap modes have you used. Perhaps use repeat instead of clamp.
i have try (sorry that forgot to mention, i using OpenGL ES 1.x)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WARP_S, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WARP_T, GL_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WARP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WARP_T, GL_CLAMP_TO_EDGE)
both not helping.
maybe i miss something?
glTexParameter is affect the texture object right? should set before load the texture data into buffer.
I used to have that same problem but doesn’t do that anymore. When I was using 2D textures the only way I found to solve it was to:
Adjust the texture size to be larger than the area you want to cover and adjust the texture coordinates to cover a smaller area of the texture so that it samples existing values instead of nothing
Switch filtering to GL_NEAREST
However, I am now using 3D textures and it does not have this issue. I’m not sure if thats what fixed it, it was a while ago.
method 1 solve my problem, i have extend the each tile edge by 1 pixel. although it solve the problem, but I think it not the solution, because it void our tiled map rule and make us have to took more time and resources to recreate the graphics.
sadly that glTexImage3D are not supported on our target platform.
will go for method 2, re-design our graphics resources, use GL_NEAREST on tiled map.
thnx for reply
And any others solution are welcome.
I am using OpenGL ES 1.x
which texture border seem are not supported.
I don’t like the texture resize method either for the same reason, too much trouble. However…
If your target platform supports it, you can enable anti-aliasing fairly easy and that will help make everything look better at a distance. It does cost a little bit of performance though at high values on low end systems.
This code sets it to max available:
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
I have try this code, but it crash when me try to render the texture
so seem are not supported on my target platform.
Make sure you bind the texture you have created, I included the following line only as an example as to where you call the glTexParameterf function.
very strange, it run if I directly
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
if I use glGetFloatv then my Texture class will fail to upload the data to buffer
but even glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f) work,
the result seem nothing difference
may be because I am doing 2D(glOrthof)
bcthund is misleading you, anisotropy have nothing to do with antialiasing, and would not help in 2D front facing tiles.
bcthund is misleading you, anisotropy have nothing to do with antialiasing
Technically, anisotropic filtering is a form of antialiasing. Multisampling is also a form of antialiasing.
However, you are correct that anisotropic filtering should not affect this issue in the slightest.
Sorry for the OT nipicking…
Anisotropic filtering merely allows sharper textures when viewed at an angle compared to bi/trilinear filtering :
Sure it improves sampling quality. But in what sense it avoids sampling artifacts due to “Nyquist/Shannon frequency too high for sampling” known as aliasing ?
I was just offering advice to help solve the issue. I already gave another working solution earlier, this was just a suggestion to “possibly” improve the situation.
However, it is true that it is likely not to have much if any effect on 2D tiles.
thanks for replay
so the gaps are common issue for using texture atlas, right?
the possible solution are:
- use GL_NEAREST for texture filter
- use texture border
- do not scale the size bigger that your texture
my current solution is swtiching between GL_LINEAR and GL_NEAREST depend on my drawing object
the possible solution are:
Or put space between the items in the atlas. It’s not very hard. Two pixels of space, replicating the pixels of their adjacent edge, would be sufficient.