Skip to main content
gamedev.net
🔒 Locked

Cube Maps - applying them

Started by rlogan Jun 30, 2004 at 3:59 PM 7 replies 2.9k views
Original Post
rlogan
rlogan
I am trying to apply a cube map to a sphere with not much success...I wrote this code based on a couple of different samples that were doing roughly the same thing This loads the cubemap texture...

    glEnable(GL_TEXTURE_CUBE_MAP_ARB);

    glGenTextures(1,&envText);
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, envText);
	
    //Create the name to be loaded
	sprintf(buff, string, "posx");
    iResult = kTextureSystem.loadTexture(buff);
    applyTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,kTextureSystem.getBitmapPointer(buff));

	sprintf(buff, string, "negx");
    iResult = kTextureSystem.loadTexture(buff);
	applyTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,kTextureSystem.getBitmapPointer(buff));

	sprintf(buff, string, "posy");
    iResult = kTextureSystem.loadTexture(buff);
	applyTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,kTextureSystem.getBitmapPointer(buff));

	sprintf(buff, string, "negy");
    iResult = kTextureSystem.loadTexture(buff);;
	applyTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,kTextureSystem.getBitmapPointer(buff));

	sprintf(buff, string, "posz");
    iResult = kTextureSystem.loadTexture(buff);
	applyTexture(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,kTextureSystem.getBitmapPointer(buff));

	sprintf(buff, string, "negz");
    iResult = kTextureSystem.loadTexture(buff);
	applyTexture(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,kTextureSystem.getBitmapPointer(buff));

	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
This uses the texture to draw a sphere

    glEnable(GL_TEXTURE_CUBE_MAP_ARB);

    //Set type of auto generation of tex-coords
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB);
    glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP_ARB);

    //Enable auto generation of tex-coords
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glEnable(GL_TEXTURE_GEN_R);

    //
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    //load the texture
    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,envText);

    //Switch to texture coordinate mode
    glMatrixMode(GL_TEXTURE);

    //Draw something
    glutSolidSphere(50.0, 100, 100);

    glMatrixMode(GL_MODELVIEW);

    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    glDisable(GL_TEXTURE_GEN_R);

    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
Anything obvious missing...all I get is a grey sphere???
_the_phantom_
_the_phantom_
thats because you are using the cube map to extract a normal map, what you want todo is use it as a reflection map like so :

glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGenf(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
rlogan
rlogan
tried that...same result....

I would assume its supported on my Card
GeForce FX5950 Ultra????
_the_phantom_
_the_phantom_
why do you switch to the texture matrix before rendering?
rlogan
rlogan
here is what is there as of now

    glEnable(GL_TEXTURE_CUBE_MAP_ARB);    //Set type of auto generation of tex-coords    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);    glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);    //Enable auto generation of tex-coords    glEnable(GL_TEXTURE_GEN_S);    glEnable(GL_TEXTURE_GEN_T);    glEnable(GL_TEXTURE_GEN_R);    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);    //load the texture    glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,envText);    //Draw something    glutSolidSphere(5.0, 100, 100);    glDisable(GL_TEXTURE_GEN_S);    glDisable(GL_TEXTURE_GEN_T);    glDisable(GL_TEXTURE_GEN_R);    glDisable(GL_TEXTURE_CUBE_MAP_ARB);
rlogan
rlogan
Anyone...is there a chance its not supported on my card...I seriously doubt it...maybe its just the drivers I'm using...I would expect to see something....even if its wrong..???

GeForce FX5950 Ultra
CRACK123
CRACK123
Hey,

Isn't cubemaps an extension ? You could just get the extensions string and check if its supported. I seriously would doubt though cos my Geforce MX 4000 supports it.

The more applications I write, more I find out how less I know
rlogan
rlogan
come to think of it, the example I based this code on is an nvidia demo which runs on my nachine...duh!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.