PDA

View Full Version : blending question



XFire
09-15-2002, 03:25 AM
Hi folks,
i have some RGBA textures containing fonts and sprites, which i like to fade in/out.
I know, i could modify the alpha value of the texture and load it again using glTexSubimage2d(), or i could create a new texture for each level of transparency.

I am not verry happy with both solutions, because updating too much textures leads to a noticeable performance hit, and creating each texture up to 16 times is rather memory expensive...

Is there an other way to draw a texture with dynamic alpha values?
Please let me know and thank's in advance,
Mike

By the way, i am using OpenGL 1.2 on a geforce 2 powered pc - not an infinite reality4 powered onyx - unfortunatly...


[This message has been edited by XFire (edited 09-15-2002).]

Mazy
09-15-2002, 04:16 AM
use the GL_MODULATE together with a colors alpha value.

the resultig alpha = textureAlpha * ColorAlpha.. then just change the colors alpha per frame

XFire
09-15-2002, 04:23 AM
Hi Mazy,
thank's for the quick response!
How do i have to use GL_MODULATE?

Thank's in advance...

Mezz
09-15-2002, 04:42 AM
Look up the glTexEnv() commands I think - that's where you'll specify GL_MODULATE to work with your texturing and the alpha of the primary colour.

-Mezz

XFire
09-16-2002, 09:18 AM
Hi Mezz,
thank's for the info about glTexEnv, i'll try to get it to work...

Deiussum
09-16-2002, 10:12 AM
GL_MODULATE is the default state, so you should just be able to enable blending, then change the alpha of the current color with glColor4*.

Edit:
Just thought I should note that if lighting is enabled then you'd have to either change the alpha of the material properties, or use glColorMaterial to be able to change it with glColor4*.


[This message has been edited by Deiussum (edited 09-16-2002).]

Leyder Dylan
09-17-2002, 08:03 AM
For use GL_MODULATE :

glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, Texture_BMP[1]);
glEnable(GL_TEXTURE_2D);

XFire
09-17-2002, 01:17 PM
Hi again,

thank's alot for the hints!
I played around with glTexEnv and found some nice results (my favorite is the mushroom like GL_BLEND parameter http://www.opengl.org/discussion_boards/ubb/smile.gif ) but i was not able to change the alpha values/level of transparency for the texture.
Looks like i do something wrong...

Deiussum, i use glColor3f() to set the color of a texturemapped font. As soon as i use glColor4f() the transparent texels (alpha values are already set) become visible. (slightly transparent, depending on the alpha value).
But as soon as i use glColor3f() the characters are displayed propper.
An other strange behaviour...

Leyder Dylan, is it save to use ARB funktions? Are they available on every OpenGL 1.2 implementation? Or only on those from the ARB companys?
Please let me know.

Well, thanks so far for your ideas, but i still need to know how to change the alpha values for solid texels only on a RGBA texture.
Please post a repy if you have any ideas and thank's in advance,
Mike

Leyder Dylan
09-17-2002, 04:56 PM
I think that the multitexturing is available on the most of video card. Just can just make a check when running your program.

You can to, use alpha test for displaying a polygon (a tree, ...) in multitexutring. I've not tryed yet but you can try it.

Leyder Dylan
09-17-2002, 04:59 PM
For using alpha test, I've a demo on my site. It loads a tree with alpha test, in fact, it's a sprite.
http://ibelgique.ifrance.com/Slug-Production/

Or in your InitGL() function :

// Spécifique au test du cannal Alpha
glAlphaFunc(GL_GREATER, 0.3f);

// On active le canal alpha
glEnable(GL_ALPHA_TEST);

When you load your sprit, no special things to add.
Your file must have a alpha chanel, for that I add the chanel with Paint Shop Pro.

XFire
09-18-2002, 11:57 AM
Hi again...
Leyder Dylan, theres some verry interresting stuff on your site! Thank's for the link.
I've took a look on the alpha demo.

I am already able to display my sprites with transparent texels. But i need to know how to change the alpha values of the solid texels only.
As already sayed, i don't like to compute new alpha values for each frame and update all my textures using glTexSubimage (because the performance decreases noticeable). An other idea would be to create each texture for each level of transparency - but this would waste a lot of texture memory....

Anyway, thanks for the info!
I think i'd better post this question at the advanced forum...

Deiussum
09-18-2002, 12:50 PM
If you want the alpha to be the same over the entire texture, it should work to use GL_MODULATE mode to modulate with the current color, or material color, and then just change the alpha on that.

Example when not using lighting:



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // This is the default mode
glColor4f(1.0, 1.0, 1.0, desiredAlpha);
glBindTexture(GL_TEXTURE_2D, nTexID);
DrawTexture();


Modify desiredAlpha, and the entire textured object will be modulated to provide the transparency.

It sounds like maybe that's not what you want, though? If it's not the only other options would be those you listed, or to use multi-texturing techniques to blend with another texture, which still brings you back to needing multiple textures for the varying alphas.

XFire
09-19-2002, 02:07 PM
Hi again,
its working fine now http://www.opengl.org/discussion_boards/ubb/smile.gif

Deiussum, the problem was that i used glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
instead of
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Thank you verry much!