Sign in to follow this  
arbuckle911

OpenGL opengl cube maps

Recommended Posts

You can find all you need at ARB_texture_cube_map

but i'll summarize a bit to the best of my knowledge


//you generate the texture as normal

unsigned int CubeName;

glGenTextures(1, &CubeName)

//then you bind it "like normal" except with a different constant for your target

glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, CubeName);
// NOTE: with newer versions of glext.h GL_TEXTURE_CUBE_MAP_ARB may NOT be
// valid because the extension has been promoted to core
// (I actually dont know if it's been promoted, but its probable)
// and thus you should use GL_TEXTURE_CUBE_MAP instead
// I will no longer make note of it, but all other constants
// that end in _ARB, may or may not need the _ARB
// (either they all will need it or they all will not)
// and theres also a good chance both will be valid

//Then you load the texture images for each cube map face

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, pxData);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, nxData);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, pyData);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, nyData);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, pzData);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, nzData);

//where pxData, nxData, pyData, nyData, pzData, and nzData are the positive x, negative x, positive y, negative y, positive z, and negative z cube faces, respectively

//you enable cube mapping with:
glEnable(GL_TEXTURE_CUBE_MAP_ARB);

//and you set up your texture coordinate generation so that the cube is sampled
//properly

//for a reflection cube map
glTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGenfv(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

//for a "normal" cube map

glTexGenfv(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB);
glTexGenfv(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB);
glTexGenfv(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);


//note that you MUST supply the normals of your primitive in order for the texture generation to work properly





and this is cubemapping to the best of my knowledge

EDIT: of course, if you're asking how to bind it to a cg program samplerCUBE, i'm of no use to you atm (of course i may have been of no use anyways haha)


hope that helps
-Dan

Share this post


Link to post
Share on other sites
Doh!
I thought it was alot more complicated than that.
Thanks.

Btw.
Is it possible to bind a single face on the cube map as a normal GL_TEXTURE_2D?
That way I wouldn't have ot load it twice, and save some memory.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this