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
}
}