I have got the problem that I want to blend two textures together before mapping them onto a poly. The blending works fine, but when I try to to use glColor(0,1,0,1) to tint the resulting texture in this case green nothing happens. I think it must something have to do with the environment sate or something like that. probably it's just one more line of code but I just can't find the problem. Here is the code snippet:
// Texture Stage 1
// Perform a linear interpolation between the output of stage 0
// (i.e texture0) and texture1 and use the RGB portion of the vertex's
// color to mix the two.
//------------------------
float mycolor[4];
mycolor[0]=mycolor[1]=mycolor[2]=0.0; //RGB doesn't matter since it's not used
mycolor[3]=blend; //Set the blend factor with this
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mycolor);
// << maybe here is something like another glTexEnvi(...) neccessary
glColor4f( 0, 1, 0, 1 ); // tying to tint the resulting mixed texture green but it's not working
Thank you very much for your help. I am new to OpenGL but I need this code to work for an assignment at my university.
Thanks for the fast reply ... but it didn't help me ... because it's very limited information and I am not understanding everything.
[/quote]
It has the info you need though:
If pname is GL_TEXTURE_ENV_COLOR, params is a pointer to an array that holds an RGBA color consisting of four values. The values are clamped to the range [0, 1] when they are specified. C[sub]c[/sub] takes these four values.
The initial value of GL_TEXTURE_ENV_MODE is GL_MODULATE. The initial value of GL_TEXTURE_ENV_COLOR is (0, 0, 0, 0).
[/quote]
[color=#1C2837][size=2][color=#000088]float[color=#000000] mycolor[color=#666600][[color=#006666]4[color=#666600]];[color=#000000]
mycolor[color=#666600][[color=#006666]0[color=#666600]]=[color=#000000]mycolor[color=#666600][[color=#006666]1[color=#666600]]=[color=#000000]mycolor[color=#666600][[color=#006666]2[color=#666600]]=[color=#006666]0.0[color=#666600];[color=#000000] [color=#880000]//RGB doesn't matter since it's not used[color=#000000]
mycolor[color=#666600][[color=#006666]3[color=#666600]]=[color=#000000]blend[color=#666600];[color=#000000] [color=#880000]//Set the blend factor with this[color=#000000]
glTexEnvfv[color=#666600]([color=#000000]GL_TEXTURE_ENV[color=#666600],[color=#000000] GL_TEXTURE_ENV_COLOR[color=#666600],[color=#000000] mycolor[color=#666600]);
From what I can tell [font=CourierNew, monospace][size=2]glColor4f does not effect the texture at all, only the colour given to glTexEnvfv does. So RGB does matter![/font]
[font=CourierNew, monospace][size=2]Looks like it also needs to be used in conjunction with [/font]GL_BLEND.
If you want to multiply with a color you need GL_MODULATE on texture image unit 0
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor4f(x, y, z, w);
Sig: http://glhlib.sourceforge.net an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
If you want to multiply with a color you need GL_MODULATE on texture image unit 0
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor4f(x, y, z, w);
Thanks a lot ... I will try out your tips as soon as possible.
Using the code above I have only been able to tint the first of the two textures and then blending them together. I haven't been able yet to tint the result of the combination of both textures. D: