Jump to content
  • Advertisement
Sign in to follow this  
fahlen

cubemap problem when not using mipmapping

This topic is 4667 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

Hi! I was wondering if anyone can spot what I'm doing wrong. When using the code below, I get black color back whenever I do a texture lookup. However, if I generate mipmaps for each face I get the expected image. The texture lookup is performed in GLSL doing textureCube(cubeMap, R).rgb where cubeMap is declared as samplerCube. I have a GeForce 6800GT and Linux graphics driver 1.0-7676 installed. Having the minification filter set to GL_LINEAR should make all texture lookups access only level 0 of the texture, especially as no texture lod bias is given in the textureCube call in the shader. I'd be very grateful for any input regarding what I may be doing wrong.
GLuint createCubeMap(const CVector3& eye, unsigned int size)
{
	GLfloat dirUpVecs[6][6] = {
		{  1.0,  0.0,  0.0, 0.0, -1.0,  0.0 },
		{ -1.0,  0.0,  0.0, 0.0, -1.0,  0.0 },
		{  0.0,  1.0,  0.0, 0.0,  0.0,  1.0 },
		{  0.0, -1.0,  0.0, 0.0,  0.0, -1.0 },
		{  0.0,  0.0,  1.0, 0.0, -1.0,  0.0 },
		{  0.0,  0.0, -1.0, 0.0, -1.0,  0.0 }
	};
	
	GLuint cubeMap, rb, fb;
	
	// Initialize color cube texture -----------------------------------
	glGenTextures(1, &cubeMap);
	glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMap);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_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);

	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA8, size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA8, size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA8, size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA8, size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
	glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA8, size, size, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);

	// Initialize depth renderbuffer -----------------------------------
	glGenRenderbuffersEXT(1, &rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, size, size);

	// Assemble framebuffer object -------------------------------------
	glGenFramebuffersEXT(1, &fb);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
							  GL_TEXTURE_CUBE_MAP_POSITIVE_X, cubeMap, 0);
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
								 GL_RENDERBUFFER_EXT, rb);
								 
	if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
	{
		cerr << "Framebuffer object not complete..." << endl;
		exit(1);
	}

	int viewport[4];
	glGetIntegerv(GL_VIEWPORT, viewport);
	glViewport(0, 0, size, size);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(90.0, 1.0, zNear, zFar);
	glMatrixMode(GL_MODELVIEW);

	// Generate maps for all 6 sides
	for (int i = 0; i < 6; ++i)
	{
		glLoadIdentity();
		gluLookAt(eye.x, eye.y, eye.z,
				  eye.x + dirUpVecs[0], eye.y + dirUpVecs[1], eye.z + dirUpVecs[2],
				  dirUpVecs[3], dirUpVecs[4], dirUpVecs[5]);

		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
								  GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubeMap, 0);
		draw();
	}

	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

	glDeleteRenderbuffersEXT(1, &rb);
	glDeleteFramebuffersEXT(1, &fb);

	reshape(viewport[2], viewport[3]);
	return cubeMap;
}

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!