Problem about skybox shader

Hi guys,

When I try to render the skybox with GLSL, the posy texture is displayed on the bottom, and the negy texture is displayed on the top. I can’t find the reason…

Vertex shader:


#version 140

uniform mat4 g_ModelViewProjectionMatrix;

uniform vec3 g_EyePosition;

in vec3 in_Position;

out vec3 s_Texcoord;

void main()
{
	gl_Position = g_ModelViewProjectionMatrix * vec4(in_Position, 1.0);
	s_Texcoord = g_EyePosition - in_Position;
}

Fragment Shader:


#version 140
uniform samplerCube g_TexSkyBox;

in vec3 s_Texcoord;

out vec4 g_FragData0;

void main()
{
	g_FragData0 = texture(g_TexSkyBox, s_Texcoord); 
}

I don’t think thats even possible unless you’ve mixed up the images in your texture loader.

Also verify that the images are not vertically flipped, many formats (TGA,BMP) store images upside down. DDS on the other hand are not flipped (though I’m not entirely sure if/how this affects cubemapping in GL).

Then’s why I’m wondering if the shader is correct. I can guarantee all the six textures has right file.


<Cubemap>
	<PosX>
		data/texture/skybox_posx_0001.tga
	</PosX>
	<NegX>
		data/texture/skybox_negx_0001.tga
	</NegX>
	<PosY>
		data/texture/skybox_posy_0001.tga
	</PosY>
	<NegY>
		data/texture/skybox_negy_0001.tga
	</NegY>
	<PosZ>
		data/texture/skybox_posz_0001.tga
	</PosZ>
	<NegZ>
		data/texture/skybox_negz_0001.tga
	</NegZ>
</Cubemap>


for(int i = 0; i <6; ++i)
{
	glTexImage2D
		(
		GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 
		textureData.m_level, 
		textureData.m_internalformat, 
		textureData.m_width, 
		textureData.m_height, 
		textureData.m_border, 
		textureData.m_format, 
		textureData.m_type, 
		static_cast<const GLubyte *>(textureData.m_data) + textureData.m_strider * i
		);
}

ok,I flipped the textures vertically and changed the shader code. Now it gets the correct skybox.


s_Texcoord = in_Position - g_EyePosition;