Skip to main content
GameDev.net gamedev.net
🔒 Locked

Cubemap problems

Started by TraxMate Jan 15, 2012 at 12:44 AM 2 replies 3.7k views
Original Post
TraxMate
TraxMate
I'm trying to render a skybox using a cubemap but it doesn't work as expected. When I rotate the camera the skybox rotates weirdly and dissapear at the sides. Here's pictures showing the problem:

This is when the camera has not been rotated (I can translate the camera and the skybox stay the same):
cubemap1.png

In this one I have rotated the camera slighly:
cubemap2.png

As you can see it doesn't work as a proper skybox and I have no idea what the problem is.

This is my cubemap code:
// These are global variables

GLchar* CubeMapFaces[] = // cubemap faces filenames
{
"CubeMap\\pos_x.tga", "CubeMap\\neg_x.tga",
"CubeMap\\pos_y.tga", "CubeMap\\neg_y.tga",
"CubeMap\\pos_z.tga", "CubeMap\\neg_z.tga",
};

GLuint CubeMapTargets[] =
{
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
};

GLuint Textures[3];




// This is in my setup function where I load shaders and models and other initializing

// Cube map stuff
glBindTexture(GL_TEXTURE_CUBE_MAP, Textures[2]);

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);

for(GLuint i = 0; i < 6; i++)
{
ILinfo TextureInfo;
LoadImage(CubeMapFaces, &TextureInfo); // Wrapper I made for DevIL image library

glTexImage2D(CubeMapTargets, 0, GL_RGB, TextureInfo.Width, TextureInfo.Height, 0, TextureInfo.Format, GL_UNSIGNED_BYTE, TextureInfo.Data);
}
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);


// In my rendering function

// ModelView is a matrix class I've made
ModelView.Load(Camera.GetCameraMatrix(true)); // Here I load the rotation only camera matrix
glBindTexture(GL_TEXTURE_CUBE_MAP, Textures[2]); // Bind my cubemap texture
glDisable(GL_CULL_FACE); // disable face culling so the inside of the cube is rendered

// Shaders is my own shader manager class
Shaders.Bind(1); // load my cubemap shaders
Shaders.SetUniformData("modelview", GL_FLOAT_MAT4, 1, ModelView.GetMatrix()); // Set the modelview uniform
Shaders.SetUniformData("projection", GL_FLOAT_MAT4, 1, Perspective.GetMatrix()); // Set the projection uniform
SkyBox.Draw(); // Draw my skybox cube

glEnable(GL_CULL_FACE);


// And finally here is my skybox shaders

// 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);
}
V-man
V-man
gl_Position = modelview * projection * in_Vertex;


normally people do
gl_Position = projection *modelview * in_Vertex;
TraxMate
TraxMate

gl_Position = modelview * projection * in_Vertex;


normally people do
gl_Position = projection *modelview * in_Vertex;
OH wow i feel sooo stupid right now T_T. Works perfect now! How could I have missed that... Been days of raging at myself for not being able to figure out what was wrong and it turns out to be something this silly tongue.png

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.