PDA

View Full Version : cubemap problem when not using mipmapping



fahlen
10-10-2005, 09:55 AM
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);
glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP);

// 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[i][0], eye.y + dirUpVecs[i][1], eye.z + dirUpVecs[i][2],
dirUpVecs[i][3], dirUpVecs[i][4], dirUpVecs[i][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, &amp;rb);
glDeleteFramebuffersEXT(1, &amp;fb);

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