I'm trying to combine two textures using the colour of one and the alpha of another, to do this I'm using the glTexEnvf() to combine the two aspects of the textures after storing them in different texture units. But it's not working and I believe it to be caused by GL_TEXTURE1 not working as expected,
I know as a fact that the issue doesn't lie in the textures themselves as I've tested that to death and they display fine normally. This currently displays the non-alpha part of GL_TEXTURE0 as black as there appears to be no colour data being pulled from GL_TEXTURE1 (I have also tried GL_TEXTURE0+1 and the ARB version of all of this though the ARB refused to display anything)
I also know for certain that they're the exact same size, in case that might have been the issue.
void mask(){
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, images[0].textures[images[0].active_frame]);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, images[1].textures[images[1].active_frame]);
printf("%d\n", images[0].active_frame);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE1);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE0);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glBegin(GL_QUADS);
glTexCoord2f(1.0,1.0);
glVertex2f((images[0].center.x)+(images[0].width),(images[0].center.y)+(images[0].height));
glTexCoord2f(1.0,0.0);
glVertex2f((images[0].center.x)+(images[0].width),(images[0].center.y)-(images[0].height));
glTexCoord2f(0.0,0.0);
glVertex2f((images[0].center.x)-(images[0].width),(images[0].center.y)-(images[0].height));
glTexCoord2f(0.0,1.0);
glVertex2f((images[0].center.x)-(images[0].width),(images[0].center.y)+(images[0].height));
glEnd();
}
Here is my initialisation code (with unrelated things such as the devIL initalisation for getting the images for the textures, removed):
glutInit(&argc, argv);
//finish initialising openGL
glutInitDisplayMode(GLUT_RGBA);
//create the window (game mode makes it full screen, there is a fullscreen function
// but for some reason this was not working)
glutEnterGameMode();
//set the background colour
glClearColor(55/360.0f, 171/360.0f, 200/306.0f, 0.0f);
//enable textures and transparency for the QUADS
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
For context I have a struct that stores info about the textures as I have animations (i simply run through textures):
typedef struct image {
int num_of_frames;
int active_frame;
int anim_called;
int* textures;
cntr center;
//the width and height are scaled for the screen
float width;
float height;
} image;
it should display GL_TEXTURE1 only where GL_TEXTURE0 doesn't have alpha. At the moment it displays black where GL_TEXTURE0 doesn't have alpha
I have just discovered that other textures (on GL_TEXTURE0) now also have no colour, (GL_TEXTURE1 still simply doesn't display at all) here is the code i use to normally display images:
void drawimage(image* img){
//set the blending mode to allow the transparency of the image to effect the QUAD
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
//Binds the current frame of the current image (must be done before glBegin)
glBindTexture( GL_TEXTURE_2D, img->textures[img->active_frame] );
//draws the textured QUAD
glBegin(GL_QUADS);
glColor4f(1.0f, 1.0f, 10.f, 1.0f);
glTexCoord2f(1.0,1.0);
glVertex2f((img->center.x)+(img->width),(img->center.y)+(img->height));
glTexCoord2f(1.0,0.0);
glVertex2f((img->center.x)+(img->width),(img->center.y)-(img->height));
glTexCoord2f(0.0,0.0);
glVertex2f((img->center.x)-(img->width),(img->center.y)-(img->height));
glTexCoord2f(0.0,1.0);
glVertex2f((img->center.x)-(img->width),(img->center.y)+(img->height));
glEnd();
}
I have a feeling to fix this I will need to 'reset' the glTexEnvf, but I don't know how.