Drawing one texture using another's alpha

Started by
16 comments, last by DrDerekDoctors 19 years, 2 months ago
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 )
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
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?
>>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
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...
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]
Ta', I'll give it a try this afternoon. :)
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.
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]
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.

This topic is closed to new replies.

Advertisement