PDA

View Full Version : gaps between 2D tiles



codetale
11-12-2010, 06:41 AM
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

BionicBytes
11-12-2010, 06:54 AM
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.

codetale
11-12-2010, 08:38 AM
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.

bcthund
11-12-2010, 04:01 PM
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:

1) 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

2) 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.

codetale
11-13-2010, 04:28 AM
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.

mfort
11-13-2010, 09:29 AM
Use texture borders.

codetale
11-13-2010, 02:14 PM
I am using OpenGL ES 1.x
which texture border seem are not supported.

bcthund
11-13-2010, 03:25 PM
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:


GLfloat fLargest;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);

glBindTexture(GL_TEXTURE_2D, myTex);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);

codetale
11-14-2010, 06:30 AM
I have try this code, but it crash when me try to render the texture

so seem are not supported on my target platform.

bcthund
11-14-2010, 01:46 PM
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.


glBindTexture(GL_TEXTURE_2D, myTex);

codetale
11-15-2010, 12:46 AM
very strange, it run if I directly
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
without
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
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)

ZbuffeR
11-15-2010, 02:53 AM
bcthund is misleading you, anisotropy have nothing to do with antialiasing, and would not help in 2D front facing tiles.

http://www.opengl.org/wiki/Multisampling

Alfonse Reinheart
11-15-2010, 03:13 AM
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.

ZbuffeR
11-15-2010, 04:27 AM
Sorry for the OT nipicking...

Technically, anisotropic filtering is a form of antialiasing.
Anisotropic filtering merely allows sharper textures when viewed at an angle compared to bi/trilinear filtering :
http://www.fszone.org/imgs/7/Anisotropic_compare.jpg
http://common.ziffdavisinternet.com/util_get_image/1/0,1425,sz=1&i=16305,00.jpg
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 ?

bcthund
11-15-2010, 02:55 PM
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.

codetale
11-16-2010, 10:12 PM
thanks for replay

so the gaps are common issue for using texture atlas, right?
the possible solution are:
1. use GL_NEAREST for texture filter
2. use texture border
3. 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

Alfonse Reinheart
11-16-2010, 10:22 PM
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.