Jump to content
  • Advertisement
Sign in to follow this  
*electriZer*

OpenGL Multitexturing - Overwriting transparent areas with RGB

This topic is 2530 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

Hey,

I'm new to OpenGL and 3D Game developement ( ~ 2months)

I am creating a tiny 3D engine for education purposes - It was going on fine, but now I have problems with Multitexturing.
I'v ripped a model from a game and converted it to wavefront .obj
With just 1 texture it looks very nice but when I'm loading the second texture the problems start.

The second texture has the same size as the first, but it has more alpha chanells because the second texture is just for some hairs and teeths.
I've got some combinations of glTexEnv with GL_COMBINE etc.
The first Texture replaced the second texture at the colored area and the transparent areas (of the second texture) where still there.
But it should be the opposite, it should show me the RGB of the first texture at the transparent area of the second texture, and the second texture (hairs, teeths, cloths) should be drawn over the first texture.

here is my rendering part of the texture :

if(obj.obj.texture_id.size() > 0)for(int text_id = 0;text_id < obj.obj.texture_id.size(); text_id++){
glActiveTexture(33984+text_id); // 33984 = GL_TEXTURE0
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, obj.obj.texture_id[text_id]);
if(text_id==0){ // First texture
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
}else if(text_id==1){ // second texture
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SOURCE0_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SOURCE1_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE); // To replace the Color of the first texture
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE); // To 'neutralize' the alpha channel
}
}

Share this post


Link to post
Share on other sites
Advertisement
It sounds like you need INTERPOLATION

GL 1.3 code and also GL 2.0 is showed here
http://www.opengl.org/wiki/Texture_Combiners#Example_:_Interpolate_tex0_and_tex1_and_multiply_the_result

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!