Jump to content

  • Log In with Google      Sign In   
  • Create Account


Multitexturing - Overwriting transparent areas with RGB


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 *electriZer*   Members   -  Reputation: 100

Like
0Likes
Like

Posted 05 January 2012 - 05:50 AM

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


Sponsor:

#2 V-man   Members   -  Reputation: 801

Like
0Likes
Like

Posted 05 January 2012 - 06:08 AM

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
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);

#3 *electriZer*   Members   -  Reputation: 100

Like
0Likes
Like

Posted 05 January 2012 - 06:41 AM

This one also don't works.

[Edit]
Ok i see, at the top of the page they wrote that's incompatible with opengl 3+
I'll try it with shaders

#4 V-man   Members   -  Reputation: 801

Like
1Likes
Like

Posted 05 January 2012 - 10:39 AM

You can create an old context if you want and still use old GL.
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);

#5 *electriZer*   Members   -  Reputation: 100

Like
0Likes
Like

Posted 05 January 2012 - 04:45 PM

Yes but I need a solution wich is compatible with GL 3 and higher




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS