Jump to content
  • Advertisement
Sign in to follow this  
DrDerekDoctors

Drawing one texture using another's alpha

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

Is it possible to draw a polygon with one texture but using another texture's alpha? ie, if I had a sprite of a man which an alpha and a fire texture, I'd draw a man-shaped blob of fire texture? I should point out it's for a 2D engine rather than anything fancy. (it's for teleport and power up effects, basically, for this game http://www.duketastrophy.demon.co.uk/exolon01.jpeg )

Share this post


Link to post
Share on other sites
Advertisement
im not sure how but my advise is not to bother

use a 32bit .tga, its RGBA so every pixel already has a alpha value. you can set you transparency in photo shop or somehting. works just as good as joining two images but is easyer and faster becouse the messy calculation are done beforehand

Share this post


Link to post
Share on other sites
Quote:
Original post by Kaze
im not sure how but my advise is not to bother

use a 32bit .tga, its RGBA so every pixel already has a alpha value. you can set you transparency in photo shop or somehting. works just as good as joining two images but is easyer and faster becouse the messy calculation are done beforehand


The whole idea is to do it realtime so that I can animate the image. For instance I might have a teleportation fuzz that I want to scroll across the shape of the man while fading up it's alpha or something, so not bothering isn't really an option. Unless, of course, it turns out to be absolute arse of a problem to overcome. I'm hoping it's just a matter of multitexturing?

Share this post


Link to post
Share on other sites
>>Is it possible to draw a polygon with one texture but using another texture's alpha?<<

very easy with glsl, eg tex0.rgba * tex1.a

Share this post


Link to post
Share on other sites
Meeep! Thanks, what sorta' speed hit does using glsl have d'you know? And is it something that only recent gfx cards support as I'm aiming for kind of a lowest common denominator for the engine...

Share this post


Link to post
Share on other sites
Quote:
Original post by DrDerekDoctorsI'm hoping it's just a matter of multitexturing?

0 alpha on the original texture and GL_ADD the other texture's alpha with GL_ALPHA_COLOR as operand on your target?

Looks to me like it'll work, then again I just woke up. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by DEVLiN
Quote:
Original post by DrDerekDoctorsI'm hoping it's just a matter of multitexturing?

0 alpha on the original texture and GL_ADD the other texture's alpha with GL_ALPHA_COLOR as operand on your target?

Looks to me like it'll work, then again I just woke up. [smile]


Could you show the code please. (i am intersted in this too.) Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by snisarenko
Could you show the code please. (i am intersted in this too.) Thanks.

I can give a useful link to code showing how to use it: (help to self-help[smile])
Multitexturing with OpenGL - (first result when googling for "multitexturing opengl" btw)

It should get you started, if nothing else. [smile]

The topic to focus on would be GL_ADD and GL_ALPHA_COLOR.

Good luck! [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by DEVLiN
Quote:
Original post by DrDerekDoctorsI'm hoping it's just a matter of multitexturing?

0 alpha on the original texture and GL_ADD the other texture's alpha with GL_ALPHA_COLOR as operand on your target?

Looks to me like it'll work, then again I just woke up. [smile]

Would work for sure, but it would be alot more flexible to use GL_REPLACE and just replace the alpha instead of relying on the other texture having a zero alpha channel.

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);

Unless I made a mistake, the code above will take the RGB channel from tex0 and the alpha channel from tex1, independent of the values of the other channels.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!