PDA

View Full Version : cube mapping



Ewik
08-27-2004, 12:08 AM
Hi,

I'm trying to do a simple sample of cube mapping.
Here is the code:


void init() {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_DEPTH_TEST);

glGenTextures(1, &cubeMapId);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapId);

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

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

const char* name[6] = {
"xpos.jpg",
"xneg.jpg",
"ypos.jpg",
"yneg.jpg",
"zpos.jpg",
"zneg.jpg"
};
img::Image2D *textureImage;

for(int i = 0; i < 6; ++i) {
textureImage = new img::Image2D(name[i]);

gluBuild2DMipmaps(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
GL_RGB8,
textureImage->width,
textureImage->height,
GL_RGB,
GL_UNSIGNED_BYTE,
textureImage->pixels
);
delete textureImage;
}

glEnable(GL_TEXTURE_CUBE_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
}

void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glutSolidTeapot(0.8);

glutSwapBuffers();
}

Here, all work fine, but when i use glTexImage2D in place of gluBuild2DMipmaps, it dosen't work, there is no texturing. I use square textures of size 256x256, or 64x64. What's wrong ?

thx.

Tom Nuydens
08-27-2004, 02:53 AM
This is hardly an advanced question. The default texture filter is NEAREST_MIPMAP_LINEAR. If you don't supply mipmaps, you have to make sure you set TEXTURE_MIN_FILTER to either NEAREST or LINEAR. This applies to all textures, not just cube maps.

-- Tom