PDA

View Full Version : Cannot correctly render sky box



shapeare
03-21-2012, 07:43 AM
I want to render a skybox with the following cubemap:
http://graphicsprojects.files.wordpress.com/2011/10/uffizi_gallery_original_image.jpg

I defined a cube with the following code:


const float R = 50.0;
GLfloat vSkyBox[] = {R, -R, R, R, -R, -R, R, R, R, R, R, -R,
-R, -R, -R, -R, -R, R, -R, R, -R, -R, R, R,
-R, R, R, R, R, R, -R, R, -R, R, R, -R,
R, -R, R, -R, -R, R, R, -R, -R, -R, -R, -R,
-R, -R, R, R, -R, R, -R, R, R, R, R, R,
R, -R, -R, -R, -R, -R, R, R, -R, -R, R, -R
};

which is a cube centered at the origin with the edge length 100.

The draw calls are as follows:


void CubeDraw(void){
glBindVertexArray(cubeVao);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 16, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 20, 4);
glBindVertexArray(0);
}


And my vertex and fragment shader:


#version 130

in vec4 vVertex;
uniform mat4 mvpMatrix; // Transformation matrix

// Texture Coordinate to fragment program
out vec3 vVaryingTexCoord;

void main(void)
{
// Pass on the texture coordinates
//vVaryingTexCoord = normalize(vVertex.xyz);
vVaryingTexCoord = vVertex.xyz/50.0 * 0.5 + vec3(0.5, 0.5, 0.5);

gl_Position = mvpMatrix * vVertex;
}




#version 130

out vec4 vFragColor;

uniform samplerCube cubeMap;

in vec3 vVaryingTexCoord;

void main(void)
{
vFragColor = texture(cubeMap, vVaryingTexCoord);
}


However, a snapshot from my program is like:
http://graphicsprojects.files.wordpress.com/2011/10/cube.png

And another one taken from inside of the cube:
http://graphicsprojects.files.wordpress.com/2011/10/cube2.png

Where does the error comes from?