PDA

View Full Version : how to mix TEXTURE_2D and cube map texture in the one single pass of the multitexture



Sourpotato
10-30-2004, 12:19 AM
I have this code to render a simple cube. the texture0 is simple texture 2d map then i decide to add reflection by using cubemap .as result i get rather weird effect.This is important ,for example ,i have one 3d model with skinned texture. now i want to add reflection to the model.but i don't know how to mix 2d texture and cube map texture.is there any simple solution here ?

the code is very simple.

glEnable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D,texid2);



glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,cube_texid);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glScalef(0.5f,0.5f,0.5f);
DrawCube();
glScalef(2.0f,2.0f,2.0f);

Anyone has any idea?

Twixn
10-30-2004, 04:30 AM
Well, looks like your enabling the cube map texture type too fast, and actually enabling Cube Maps on Texture0, not on Texture1.

it would be better to do it like this:

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,texid2);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,cube_texid);

"glActiveTextureARB()" Lets you choose what Texture Unit to work with, if you want do anything to that texture, like loading etc, you have to do it *After* "glActiveTextureARB()".

Also:

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_CUBE_MAP_ARB);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

would be the disabling code.

Hope that makes sence to you.

Twixn

houdy
10-30-2004, 04:32 AM
simple to say, you need two textures, one for base texute ,one for normal texture, and you should create a cube map used for normalize vector.
then, combine the cube map with normal texture by dot3 operation and then moduate the result with the base texture.

Sourpotato
10-30-2004, 06:09 AM
Thankx mate ,Now i understand The GlEnable GLDisable Pair is the key to the render multitexture properly.

Now , i got that i have to use texture_env_combine AND texture_env_dot3 to modulate the two textures. For example ,if i want to 0.3 * texture0_color + 0.7 * texture1_color . how can i use this two extension to achieve this effect.

i have to say the texture_env_combine extension seem to be extremely complex and i don't understand why i have to do the dot3 product between the two texture color?

Twixn
10-30-2004, 05:03 PM
I think houdy is thinking that you are using the cube as a 'Normalization Cube Map', its a bump mapping techique using the dot3 extension...i dont think u actually need to use Dot3 as your only using simple Multitexture of one diffuse texture map and a diffuse cube map ('Diffuse' meaning just colour, no fancy lighting effects etc).

I agree, The texture_env_combine extension can get pretty tricky when your starting out.

take alook at the Registry doc:
http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt

particularly the 'Overview' section near the top.
I think what your looking for is the "INTERPOLATE_ARB" combine option.

If your still confuzed or having trouble, i'll find some tutorials for you if you need them.

Twixn

Sourpotato
10-30-2004, 06:29 PM
Oh my,Twixn ,you are really helpful. thanx.
I got my problem solved ,simply by using glTexEnvi( GL_TEXTURE_ENV ,GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_ADD );

since the effect is not modulation between two textures .the multi texture does look much brighter.