Jump to content
  • Advertisement
Sign in to follow this  
hesselKRaymond

OpenGL MultiTexture Problem

This topic is 2614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

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 0
// Simply output texture0 for stage 0.


glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( text01.getTextureData().textureTarget );
glBindTexture( text01.getTextureData().textureTarget, text01.getTextureData().textureID );

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

// 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.

glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable( text02.getTextureData().textureTarget );
glBindTexture( text02.getTextureData().textureTarget, text02.getTextureData().textureID );

glTexEnvi( 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_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_CONSTANT );

//------------------------
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.

Raymond

Share this post


Link to post
Share on other sites
Advertisement

[quote name='bluntman' timestamp='1305822484' post='4813057']
Read this.


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.

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
In that case, you would need another texture image unit. YOU MUST BIND A TEXTURE to the unit and enable the unit.


glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, someTexture);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );

float [/font]multColor[4];
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, multColor);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!