Mult-texturing + masking

Started by
6 comments, last by TomasH 19 years, 8 months ago
hi i wanna do multi texturing and do maksing together how would i do this? assuming i have background.bmp ball.bmp ballmask.bmp i know i have to use glBlendFunc(GL_ONE,GL_ONE); glBlendFunc(GL_DST_COLOR,GL_ZERO); but where would i use it in a mult-texture? ques 2: wut does GL_TEXTURE0_ARB these mean? there are GL_TEXTURE(0 to 31)_ARB of these. do i use theses to control the blend function? thx for the help.
Advertisement
Look at some multitexturing tutorial as it's a little more complicated because of extensions and such.
Draw a quad textured with the mask texture(black&white) using
glBlendFunc(GL_DST_COLOR,GL_ZERO),than draw another quad over this one textured with the real texture that must have a black backgroun which won't show up and the colored image) that will go over the black part of the previous image (use glBlendFunc(GL_ONE,GL_ONE)this time)
could u show me how to do that using this?


glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);

glActiveTextureARB(GL_TEXTURE3_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[2]);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);

glBegin(GL_QUADS);

// Now, instead of using glTexCoord2f() we use glMultiTextCoord2fARB() to
// specify the texture coordinates for each texture. This allows us to move
// one texture to a totally different place on the geometry. A perfect example
// of this is shadows. glMultiTexCoord2fARB() takes the texture ID we wish
// to specify, with it's texture coordinates afterwards. We just use the same
// texture coordinates for each texture.

// Display the top left vertice with the texture coordinates for both textures
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0.0f, 1.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
glVertex2f(-1*32, 1*32);

// Display the bottom left vertice with the textures for both textures
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0.0f, 0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
glVertex2f(-1*32, -1*32);

// Display the bottom right vertice with the textures for both textures
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 1.0f, 0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f);
glVertex2f(1*32, -1*32);

// Display the top right vertice with the textures for both textures
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 1.0f, 1.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f);
glVertex2f(1*32, 1*32 );

// Stop drawing
glEnd();
Here's a couple of tutorials that might help you understand multitexturing. [smile]
link
link
thx for the help... but they both are confusing...

can someone explain how the GL_TEXTURE2_ARB extensions work?
Quote:Original post by tomba
can someone explain how the GL_TEXTURE2_ARB extensions work?

GL_TEXTUREx_ARB refers to a texture unit. You have a number of these, depending on what gfx card you have. You can enable each of these separately and set up how they should be combined with the other texture units and the vertex color.
Here's some code I wrote:
  glActiveTextureARB(GL_TEXTURE0_ARB);  glEnable(GL_TEXTURE_2D);  glBindTexture(GL_TEXTURE_2D,textures[0]);  glfwLoadTexture2D("normalmap.tga",0);  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);  glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB);  glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_DOT3_RGBA_ARB);  glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PRIMARY_COLOR_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);


We start by selecting texture unit:
  glActiveTextureARB(GL_TEXTURE0_ARB);

Then we enable that unit, bind a texture object, load a texture and set filters:
  glEnable(GL_TEXTURE_2D);  glBindTexture(GL_TEXTURE_2D,textures[0]);  glfwLoadTexture2D("normalmap.tga",0);  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

Then it's time to say how this texture should be applied. In this case I'm doing DOT3 bump mapping, so I say that it's the operation I want to do:
  glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_ARB);  glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB,GL_DOT3_RGBA_ARB);

The DOT3 operation uses two sources. We set the first to be the primary color - i.e. the one set by glColor (or lighting)
  glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,GL_PRIMARY_COLOR_ARB);  glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,GL_SRC_COLOR);

You see that we had to write two lines, one to say that we want to use the primary color as source, and a second to say that we want the RGB of it.
Then we setup the second source. We want it to be the RGB of this texture, so we set source and operand to GL_TEXTURE and GL_SRC_COLOR.
  glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,GL_TEXTURE);  glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,GL_SRC_COLOR);


Hope that helps! Try rereading the tutorials, especially the first one I posted, and you'll hopefully be less confused.

[Edited by - TomasH on August 22, 2004 1:37:03 PM]
One more thing: You'll probably need to store the mask as alpha, as it otherwise would be hard to solve this.. In that case you might actually just add an alpha channel to your texture instead of using multitexturing to combine the texture and the mask (unless you have several different masks for each picture.)

This topic is closed to new replies.

Advertisement