What is causing these dots (in some cases it's a line, it depends on camera angle) to appear on the edge of my texture that i map on a half-sphere or sphere? When i map the same texture on a half-cylinder it works fine, there are no dots (line).
This is how it looks:
This is how i set my texture params:
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);
This is how i draw my half-sphere:
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++;
}
}
I finally managed to resolve this. Issue was that I used single GL_TRIANGLE_STRIP
to draw my half-sphere, which can't be used if the shared vertices have different texture coordinates, in that case you need to use GL_TRIANGLES
. I found out about this on this site.