Jump to content
  • Advertisement
Sign in to follow this  
TraxMate

Cubemap problems

This topic is 2524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
gl_Position = modelview * projection * in_Vertex;


normally people do
gl_Position = projection *modelview * in_Vertex;

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!