PDA

View Full Version : ARB Multi-Texture Woes



jmmistrot
03-05-2003, 09:04 AM
I could use some help.. I have searched this site and others employin what I have to try and get this to work and I am getting really discouraged at this point..
I have a sphere I have been trying to test out different texturing techniques with.
Currently I am trying to use multitexturing. I would like to place two textures on my model.
The first has an all white alpha channel and acts as the base texture of the object.
The second image has black dots on its alpha to let the base show through.
So when I try all of the stuff below all I get is the last texture drawn. Where the Alpha is 0 I can see through to the backfaces,
no sign of the base texture. Where the alpha is 1, I can see the color of the decal map drawn translucently with the backfaes showing through.
I have a GeForce 2MX..OsX Jaguar.4
I am using tiffs..


Create Textures---->>
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, image0->width, image0->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image0->raster);

glGenTextures(1, &texture[1]);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 4, image0->width, image0->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image0->raster);


GLinit------>>
glClearColor(0.0, 0.0, 0.0, 1.0);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
LightInit---->>
//all these guys alpha values are 1//
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // add lighting. (ambient)
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // add lighting. (diffuse).
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // set light position.
glEnable(GL_LIGHT1); // turn light 1 on.

glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);

DrawRoutine----->>>

glDisable(GL_DEPTH_TEST);

glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_LINE);//I enable this to see whats going..

glEnable(GL_TEXTURE_2D);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_ALPHA_TEST);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DE CAL);

model->draw();
//in the model's draw routine I pass texture coordinates like this: //glMultiTexCoord2fARB(GL_TEXTURE0_ARB, vt_array[(vtIndex[k])][0],vt_array[(vtIndex[k])][1]);
//glMultiTexCoord2fARB(GL_TEXTURE1_ARB, vt_array[(vtIndex[k])][0],vt_array[(vtIndex[k])][1]);

DFrey
03-05-2003, 10:15 AM
You might want to get a look at an example I made. http://bellsouthpwp.net/d/f/dfrey69/multitex_example.zip

It requires a Geforce 3 or better as is and is written for Windows, but it should provide some clue as to what you want to do. The interesting bits are at the end of the main.cpp file. This example does essentially what you want, but also blends in an environment map, and lighting in 2 more stages. So just replace the stage 1 code with the stage 2 code, and remove the stage 3 code altogether. Oh and it requires at least OpenGL 1.3.

[This message has been edited by DFrey (edited 03-05-2003).]

jmmistrot
03-05-2003, 02:24 PM
Unfortunately I have only a measley GeForce2MX
but I know it supports at least to texture units..I'll take a look at your code..thanks..


Originally posted by DFrey:
You might want to get a look at an example I made. http://bellsouthpwp.net/d/f/dfrey69/multitex_example.zip

It requires a Geforce 3 or better as is and is written for Windows, but it should provide some clue as to what you want to do. The interesting bits are at the end of the main.cpp file. This example does essentially what you want, but also blends in an environment map, and lighting in 2 more stages. So just replace the stage 1 code with the stage 2 code, and remove the stage 3 code altogether. Oh and it requires at least OpenGL 1.3.

[This message has been edited by DFrey (edited 03-05-2003).]

Rommel
03-05-2003, 04:34 PM
If I understand correctly, what you're trying to do is:

final.r = (texture0.r * texture1.alpha) + (texture1.r * (1 - texture1.alpha))
final.g = (texture0.g * texture1.alpha) + (texture1.g * (1 - texture1.alpha))
final.b = (texture0.b * texture1.alpha) + (texture1.b * (1 - texture1.alpha))
final.alpha = texture0.alpha

If this is the case, you'll probably need to use the ARB_texture_env_combine mechanism -- try this code instead of yours:




glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_ALPHA_TEST);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);


I havenít actually run it, but it should work. For more information on the ARB_texture_env_combine specification, see http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_env_combine.txt


[This message has been edited by Rommel (edited 03-05-2003).]