【发布时间】:2020-04-07 09:05:01
【问题描述】:
是什么导致这些点(在某些情况下是一条线,取决于相机角度)出现在我映射到半球体或球体上的纹理边缘?当我在半圆柱体上映射相同的纹理时,它工作正常,没有点(线)。
看起来是这样的:
这就是我设置纹理参数的方式:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
这就是我画半球的方式:
float x, y, z;
float s, t;
double alpha1, alpha2, beta;
for(double j = 0; j < gradation; j++) {
alpha1 = j/gradation * Math.PI;
alpha2 = (j+1)/gradation * Math.PI;
for(double i = 0; i <= gradation; i++) {
beta = i/gradation * Math.PI;
z = (float) (Math.sin(alpha1)*Math.cos(beta));
x = (float) (Math.sin(alpha1)*Math.sin(beta));
y = (float) Math.cos(alpha1);
s = (float) (beta / Math.PI);
t = (float) (alpha1 / Math.PI);
posCoords[3*newVertexIndex] = x*radius;
posCoords[3*newVertexIndex + 1] = y*radius;
posCoords[3*newVertexIndex + 2] = z*radius;
texCoords[2*newVertexIndex] = s;
texCoords[2*newVertexIndex + 1] = t;
indices[vertexCounter++] = newVertexIndex++;
z = (float) (Math.sin(alpha2)*Math.cos(beta));
x = (float) (Math.sin(alpha2)*Math.sin(beta));
y = (float) Math.cos(alpha2);
t = (float) (alpha2 / Math.PI);
posCoords[3*newVertexIndex] = x*radius;
posCoords[3*newVertexIndex + 1] = y*radius;
posCoords[3*newVertexIndex + 2] = z*radius;
texCoords[2*newVertexIndex] = s;
texCoords[2*newVertexIndex + 1] = t;
indices[vertexCounter++] = newVertexIndex++;
}
}
【问题讨论】:
-
源纹理是什么样的?
-
这是我从磁盘加载的大锅纹理。纹理很好,因为我在半圆柱体上试过它,它工作正常,边缘没有点或线。
-
1) 它是否可能在未映射的区域中包含大量白色? 2)它是否包含透明度?
-
从我发布的图片来看,点似乎是白色的,但实际上它们是绿色的,并且在某些角度也会出现绿线。当我加载不同的纹理点/线时,会变成不同的颜色。这就是这张图片的整体外观:image
-
您是否尝试将 GL_CLAMP_TO_EDGE 更改为 GL_REPEAT?