PDA

View Full Version : how to use cubemaps?



gvm
06-14-2003, 07:51 AM
hi!
i would like to use cubemaps. how to prepare textures for it and then bind it. (i have 6 textures, positivex,y,z and negativex,y,z)
here what i've done(is it right?):

glEnable(GL_TEXTURE_CUBE_MAP_EXT);
glGenTextures(6,&ids[0]);
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, ids[0]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, 0, px.HasAlpha() ? 4 : 3, px.GetWidth(), px.GetHeight(), 0, px.HasAlpha() ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, px.GetImage());
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, ids[1]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, 0, nx.HasAlpha() ? 4 : 3, nx.GetWidth(), nx.GetHeight(), 0, nx.HasAlpha() ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, nx.GetImage());
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, ids[2]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, 0, py.HasAlpha() ? 4 : 3, py.GetWidth(), py.GetHeight(), 0, py.HasAlpha() ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, py.GetImage());
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, ids[3]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, 0, ny.HasAlpha() ? 4 : 3, ny.GetWidth(), ny.GetHeight(), 0, ny.HasAlpha() ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, ny.GetImage());
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, ids[4]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, 0, pz.HasAlpha() ? 4 : 3, pz.GetWidth(), pz.GetHeight(), 0, pz.HasAlpha() ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, pz.GetImage());
glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, ids[5]);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, 0, nz.HasAlpha() ? 4 : 3, nz.GetWidth(), nz.GetHeight(), 0, nz.HasAlpha() ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, nz.GetImage());
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,GL_LINEAR);

if this is right, then how to bind them to one object???
i didn't understood that, what is written in extension's specification. plz. help

Bob
06-14-2003, 08:32 AM
You only need to generate one texture ID, because the whole cube map (that is, all six images) is a single texture object.