Jump to content
  • Advertisement
Sign in to follow this  
eVp

Using a black & white texture as alpha channel.

This topic is 3548 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 have a black and white texture that is generated by rendering to texture. Now, I'd need to use that texture as an alpha channel to another texture. I've been trying to achieve it through multitexturing but without much success. Here's something I've tried. texture0 = Wood texture texture1 = Black & White texture I want to use as the alpha channel for the wood glClientActiveTexture(GL_TEXTURE0); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2,GL_FLOAT,0,coordinates); glClientActiveTexture(GL_TEXTURE1); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2,GL_FLOAT,0,coordinates); glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, [TextureManager getTexture:kTexture_BGwood].name); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_COMBINE); //Render the background texture with lights and color glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_RGB, GL_MODULATE); glTexEnvi(GL_TEXTURE_2D, GL_SRC0_RGB, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_2D, GL_SRC1_RGB, GL_TEXTURE0); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_ALPHA, GL_MODULATE); glTexEnvi(GL_TEXTURE_2D, GL_SRC0_ALPHA, GL_PRIMARY_COLOR); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glTexEnvi(GL_TEXTURE_2D, GL_SRC1_ALPHA, GL_TEXTURE0); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, [TextureManager getTexture:kTexture_HoleLayer].name); glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_RGB, GL_REPLACE); //use previous RGB glTexEnvi(GL_TEXTURE_2D, GL_SRC0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_2D, GL_COMBINE_ALPHA, GL_MODULATE); // modulate vertex alpha with B&W textures "color" glTexEnvi(GL_TEXTURE_2D, GL_SRC0_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glTexEnvi(GL_TEXTURE_2D, GL_SRC1_ALPHA, GL_TEXTURE1); glTexEnvi(GL_TEXTURE_2D, GL_OPERAND1_ALPHA, GL_SRC_COLOR); glVertexPointer(3, GL_FLOAT, 0, vertices); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); What happens with this set-up baffles me. The end result is that the alpha is solid 1.0f everywhere (this is the alpha of both the textures). On top of that, the texture1 gets drawn (should not at all in my opinion). Its RGB gets modulated with the RGB of the wood texture. Thus i get black holes where I want see through holes. How can I make use of a B&W texture as alpha channel?

Share this post


Link to post
Share on other sites
Advertisement
Try replacing this line:
	glTexEnvi(GL_TEXTURE_2D, GL_SRC1_ALPHA, GL_TEXTURE1);
with this one:
	glTexEnvi(GL_TEXTURE_2D, GL_SRC1_RGB, GL_TEXTURE1);

Also note that this effect would be very easy if you were using shaders.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Try replacing this line:
	glTexEnvi(GL_TEXTURE_2D, GL_SRC1_ALPHA, GL_TEXTURE1);
with this one:
	glTexEnvi(GL_TEXTURE_2D, GL_SRC1_RGB, GL_TEXTURE1);

Also note that this effect would be very easy if you were using shaders.


Didn't work, but I found a way to make my b&w texture a true alpha texture and so I have everything working. By the way, shaders are sadly out of the picture on the iPhone :(

Thanks for reading - problem solved!

[Edited by - eVp on January 4, 2009 8:01:22 PM]

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!