3

I have my skybox showing: enter image description here

But there are borders of the box, which I don't want. I already searched the internet and they all said that GL_CLAMP_TO_EDGE should work, but I am still seeing the borders.

This is what I used for the texture loading:

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);

Can anyone tell me what I am doing wrong?

EDIT: enter image description here

Strange thing is that the borders are only showing at the top of the skybox. so when a skybox face, touches the roof of the box.

Here an image of it: enter image description here

Hugius
  • 380
  • 1
  • 5
  • 15
  • @WillBriggs What else should I say? This is what I used, is this wrong or not? This is a common problem but not many people can fix it. – Hugius Jan 20 '16 at 20:52
  • Clamp to edge affects what happens to texture coordinates when they get to the edge of a texture map; is each of your faces a separate map or have you put all six into a single map (presumably with a white background)? – Tommy Jan 20 '16 at 20:54
  • Do you want to have 1200 lines of code here? I already read that link a couple of times but if I don't give my whole code, you guys don't know what every function and stuff is. – Hugius Jan 20 '16 at 21:01
  • But if you guys wanna run it, including the main method, then it still would be enourmous much code. – Hugius Jan 20 '16 at 21:14
  • 2
    Maybe there are actual borders in the texture image? Maybe you can post your sky texture to check? – rodrigo Jan 20 '16 at 22:46
  • @rodrigo I updated my post, and btw I used another image for the skybox but this one also doesn't work. – Hugius Jan 21 '16 at 16:02
  • The image you posted is a composite of all 6 faces. Are you using this very same big image for the texture cube or 6 different images? – rodrigo Jan 21 '16 at 17:01

2 Answers2

4

I finally found the solution. This is a filthy mistake in the texture itself. There is a black border around the texture, but you can barely see it unless you zoom in. So I removed the borders and it worked.

Hugius
  • 380
  • 1
  • 5
  • 15
1

Its texture coordinates floating error. If you use shaders you can clean it to strict [0.0f, 1.0f]. I cannot say is there is any possible solution for OpenGL API calls. But shaders must support this. Example using HLSL 2.0 (NVIDIA Cg) for post screen shader.

float g_fInverseViewportWidth: InverseViewportWidth;
float g_fInverseViewportHeight: InverseViewportHeight;

struct VS_OUTPUT {
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD0;
};

VS_OUTPUT vs_main(float4 Pos: POSITION){
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   // Image-space
   Out.texCoord.x = 0.5 * (1 + Pos.x + g_fInverseViewportWidth);
   Out.texCoord.y = 0.5 * (1 - Pos.y + g_fInverseViewportHeight);

   return Out;
}

Where sign rutine is used for strict [0, 1] texture coord specification. Also there is sign rutine for GLSL you may use. sign retrives sign of the vector or scalar it mean -1 for negative and 1 for positive value so to pass texture coord for vertex shader it must be specified as -1 for 0 and 1 for 1 than you may use this like formulae for actual texture coord specification:

   Out.texCoord.x = 0.5 * (1 + Pos.x + g_fInverseViewportWidth);
   Out.texCoord.y = 0.5 * (1 - Pos.y + g_fInverseViewportHeight);

Here you can see texture 1 texel width inaccurancy:

enter image description here

Now with modified shader:

enter image description here

Mykola
  • 3,343
  • 6
  • 23
  • 39