PDA

View Full Version : Cubemap problem



TraxMate
01-13-2012, 07:19 PM
I'm trying to make a skybox using a cubemap but something is wrong. At first sight it appears to be working but if I rotate the camera it bugs out! Here's two pictures showing it.

Camera at origin:
http://localhostr.com/files/9ecGEFJ/cubemap1.png

Slightly rotated camera:
http://localhostr.com/files/hyD8UuX/cubemap2.png

What is it that I'm doing wrong? This is how I'm creating the cubemap texture:

// Cube map stuff
glGenTextures(1, &CubeMapTexture);
glBindTexture(GL_TEXTURE_CUBE_MAP, CubeMapTexture);

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
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);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

for(GLuint i = 0; i < 6; i++)
{
ILinfo TextureInfo;
LoadImage(CubeMapFaces[i], &amp;TextureInfo);

glTexImage2D(CubeMapTargets[i], 0, GL_RGB, TextureInfo.Width, TextureInfo.Height, 0, TextureInfo.Format, GL_UNSIGNED_BYTE, TextureInfo.Data);
}
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
And this is my shader code:
// Vertex shader
#version 400

in vec4 in_Vertex;
out vec3 TexCoord;

uniform mat4 modelview;
uniform mat4 projection;

void main()
{
TexCoord = in_Vertex.xyz;
gl_Position = modelview * projection * in_Vertex;
}


// Fragment shader
#version 400

in vec3 TexCoord;
out vec4 FragColor;

uniform samplerCube CubeMap;

void main()
{
FragColor = texture(CubeMap, TexCoord);
}