我想得出一个基本的2D地面网由来自纹理地图更小的砖(注1像素的透明边框):
I'm trying to draw a basic 2d ground mesh made up of smaller tiles from a texture atlas (note the 1 pixel transparent border):
我渲染瓷砖纹理四边形使用以下code:
I render the tiles as texture quads using the following code:
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_SHORT, 0, &m_coords[0]);
glTexCoordPointer(2, GL_FLOAT, 0, &m_uvs[0]);
glDrawArrays(GL_TRIANGLES, 0, m_coords.size() / 2);
glBindTexture(GL_TEXTURE_2D, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
的位置显然是整数坐标。 UV坐标角被计算如下:
The positions are obviously integer coordinates. The UV coordinates for the corners are calculated like this:
u0 = float(x) / float(texWidth);
v0 = float(y) / float(texHeight);
u1 = float(x+w) / float(texWidth);
v1 = float(y+h) / float(texHeight);
其中,w和h是所述砖的未经填充的大小。
Where w and h is the size of the tile without the padding.
看起来伟大的,当模型视点变换捕捉到一个整数位置(右),但是当它开始移动,我得到了瓷砖之间的黑色一样的东西(左):
It looks great when the modelview transform is snapped to an integer position (right), but when it starts to move I get black thingies between the tiles (left):
据我了解,我应该抵消UV用半纹理像素坐标,使其工作,但如果我改变UV的计算为:
From what I understand I should offset the UV coordinates with a half texel to make it work, but if I change the UV calculations to:
u0 = float(x+0.5f) / float(texWidth);
v0 = float(y+0.5f) / float(texHeight);
u1 = float(x+w-0.5f) / float(texWidth);
v1 = float(y+h-0.5f) / float(texHeight);
它仍然无法正常工作。这是做了正确的方法是什么?我是否需要融合这个工作?如果我抵消了瓷砖,以确保他们捕捉到的像素网格它的工作原理,但是这使得移动较慢时,它折断。怎样的人通常会解决这个问题?
It still doesn't work. Is this the correct way to do it? Do I need blending for this to work? If I offset the tiles to make sure they're snapped to the pixel grid it works, but that makes it snap when moving slowly. How do people usually solve this?
修改
我应该OFC说,它是在iPhone上。
I should ofc have said that it's on the iphone.
您的边界不应该是透明的,而是从每个subtexture的相对侧的像素。例如在每个子纹理的右侧的边界应该是象素的最左边的线的拷贝,也就是说,它将环绕到象素。
Your border shouldn't be transparent, but rather the pixels from the opposing side of each subtexture. For example the border on the right hand side of each sub-texture should be a copy of the left-most line of pixels, i.e. the pixels that it would wrap around to.
那你是怎么骗包装的纹理采样的边界。
That is how you "cheat" wrapping for the texture sampler on the borders.