【问题标题】:LWJGL/OpenGL Why are there dots on the edge of my texture when i map it onto half-sphere or sphere?LWJGL/OpenGL 当我将纹理映射到半球体或球体时,为什么我的纹理边缘会出现点?
【发布时间】: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?

标签: opengl lwjgl


【解决方案1】:

我终于设法解决了这个问题。问题是我使用单个GL_TRIANGLE_STRIP 来绘制我的半球体,如果共享顶点具有不同的纹理坐标,则无法使用,在这种情况下您需要使用GL_TRIANGLES。我在site 上发现了这一点。

【讨论】:

    猜你喜欢
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    相关资源
    最近更新 更多