I'm reading the SuperBible book which describe and interesting way of rendering a skybox. The Idea is to render only a plane, instead of a cube, and only change the texture coordinates depending on the Rotation of the view matrix.
However, the rotation is not correct for me, if Yaw and pitch works at startup, it then roll if I combine them.
The camera seems correct as my models does render correctly (without rolling)
Here is the code:
// -----------------------
// OpenGL Calls
glDepthFunc(GL_LEQUAL);
glDisable(GL_DEPTH_TEST);
glUseProgram(p.program);
glBindVertexArray(emptyVAO);
glUniformMatrix4fv(viewMatrixUniform, 1, GL_FALSE,
glm::value_ptr(frame.View));
glActiveTexture(GL_TEXTURE0);
glUniform1i(textureCubeUniform, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureCubeMap);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
// ------------------------
// Vertex Shader
out vec3 textureCoordinate;
uniform mat4 ViewMatrix;
void
main(void)
{
vec3[4] vertices = vec3[4](vec3(-1.0, -1.0, 1.0), vec3(1.0, -1.0, 1.0),
vec3(-1.0, 1.0, 1.0), vec3(1.0, 1.0, 1.0));
textureCoordinate = mat3(ViewMatrix) * vertices[gl_VertexID];
gl_Position = vec4(vertices[gl_VertexID], 1.0);
}
// ------------------------
// Fragment Shader
uniform samplerCube textureCube;
in vec3 textureCoordinate;
out vec4 color;
void main(void)
{
color = texture(textureCube, textureCoordinate);
}
Edit: Here is the Code of the camera
yaw += offset.x * speed * deltaTime;
pitch += offset.y * speed * deltaTime;
if (pitch > 89.0f) pitch = 89.0f;
if (pitch < -89.0f) pitch = -89.0f;
glm::vec3 direction;
direction.x = cos(glm::radians(pitch)) * cos(glm::radians(yaw));
direction.y = sin(glm::radians(pitch));
direction.z = cos(glm::radians(pitch)) * sin(glm::radians(yaw));
direction = glm::normalize(direction);
View =
glm::lookAt(position, position + direction, glm::vec3(0, 1, 0));