Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Cubemap problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 TraxMate   Members   -  Reputation: 132

Like
0Likes
Like

Posted 14 January 2012 - 06:44 PM

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):
Posted Image

In this one I have rotated the camera slighly:
Posted Image

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[i], &TextureInfo); // Wrapper I made for DevIL image library
		
	glTexImage2D(CubeMapTargets[i], 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);
}


Sponsor:

#2 cec19   Members   -  Reputation: 102

Like
0Likes
Like

Posted 16 January 2012 - 03:27 AM

Well, I don't use cube maps for implementing skyboxes, but I found something interesting about them in OpenGL.org. Maybe that is the solution for your problem.

http://www.opengl.org/wiki/Common_Mistakes#Creating_a_Cubemap_Texture

If you want I can post my code(or share a download link to it) so you can use it for your skyboxes.

#3 V-man   Members   -  Reputation: 805

Like
1Likes
Like

Posted 16 January 2012 - 04:31 AM

gl_Position = modelview * projection * in_Vertex;


normally people do
gl_Position = projection *modelview * in_Vertex;
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#4 TraxMate   Members   -  Reputation: 132

Like
0Likes
Like

Posted 16 January 2012 - 11:38 AM

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 Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS