I'm trying to implement alpha masking using opengl and multitexturing. I've an alpha image (it's RGB with no data in the alpha channel) and another image (also RGB no alpha) I'd like to mask with the alpha image. I'm using quads in the scene a ground and background quad and then a quad which represents the entity I'm trying to mask.
When I "turn on" the multitexturing code, the ground and background quads are wiped off the screen. I do see the foreground quad with image image and it's masked correctly. When I turn off the multitexturing code, the scene renders as expected, but that removes the foreground object and image (along with multitexturing).
I modified my alpha mask and found out, the multitexturing code is drawing a huge plane (inspite of my uv coordinate calculations and glVertex3f calls) with the original image and the alpha map. I kind of get the impression OpenGL is ignoring my glVertex3f call.
I've had to change GL_SOURCE0_RGB to GL_SOURCE1_RGB b/c if I don't do that I get really strange behavior from the video card (foreground object renders but the mask isn't applied and gets turned into a grey quad on the right side of the screen with a funky projection applied to it). I've tested this on 2 systems and it's the same behavior in both cases.
i'm attempting to use a fixed pipeline multitexturing technique.
GLuint alphaGLTexture;
SDL_SurfaceToGLTexture(aTexture, &alphaGLTexture);
GLuint fgGLTexture;
SDL_SurfaceToGLTexture(fgTexture, &fgGLTexture);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, alphaGLTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, fgGLTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTranslatef(0.0f, 0.0f, 0.0f);
double u_coord = 0.0f, v_coord = 0.0f;
glBegin(GL_QUADS);
glMultiTexCoord2f(GL_TEXTURE0, u_coord, v_coord);
glMultiTexCoord2f(GL_TEXTURE1, u_coord, v_coord);
glVertex3f(posax, posay, posaz);
u_coord = 1.0f; v_coord = 0.0f;
glMultiTexCoord2f(GL_TEXTURE0, u_coord, v_coord);
glMultiTexCoord2f(GL_TEXTURE1, u_coord, v_coord);
glVertex3f(posbx, posby, posbz);
u_coord = 1.0f; v_coord = 1.0f;
glMultiTexCoord2f(GL_TEXTURE0, u_coord, v_coord);
glMultiTexCoord2f(GL_TEXTURE1, u_coord, v_coord);
glVertex3f(poscx, poscy, poscz);
u_coord = 0.0f; v_coord = 1.0f;
glMultiTexCoord2f(GL_TEXTURE0, u_coord, v_coord);
glMultiTexCoord2f(GL_TEXTURE1, u_coord, v_coord);
glVertex3f(posdx, posdy, posdz);
glEnd();
glLoadIdentity();
The function, SDL_SurfaceToGLTexture, works consistently for the ground and background quads.