PDA

View Full Version : Alpha Slider Or Algorithm



list67
01-16-2004, 12:40 PM
Hi. I'd like to know of any common approaches for accomplishing the following.

A program loads a texture with glTexImage2D, and then later calls glBindTexture when drawing on a rectangle. Say someone has "slider" type of GUI that controls the alpha value of the texture. If the slider was all the way to the right, the texture would be opaque, and all the way to the left would be transparent, and in between would be some semi-transparent.

1) One way would be to recall glTexImage2D each time the slider is moved in order to change the transparency values.

2) Another way might be to use some kind of GL_MODULATE and change the alpha value of the rectangle using glColor4f?

3) Any others?

Secondly, what if instead of a simple range from transparent to opaque, the user wanted to apply some algorithm based on the values in the texture. For example, suppose the user specified 2 values (high and low) and the user wanted all the pixels in the texture that had red values above high to be opaque, and all the pixels with red values below low to be transparent, and all the pixels with red values in between high and low to be a range of transaparency from opaque to transparent.

1) The same as #1 above

2) ?

Thank you for your time.

Mike

list67
01-16-2004, 01:42 PM
Here's a possible solution to the first case: http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/001883.html

ZbuffeR
01-18-2004, 02:46 AM
1) In any case, your texture is almost the same, so instead of glTexImage2D, you can just use glTexSubImage2D to change only the pixels, not the size, type etc of the texture. It is faster.

Case 2, other possibilities :
2) if your card supports it, fragment program to change the texture lookup value to anything else. It is very powerful and flexible.

3) things like multitexturing, env_crossbar and the like, somewhat limited and complex compared to 2), but still powerful for some uses. Maybe not the for one you mentionned thought.

4) If your card/driver is listed in http://www.delphi3d.net/hardware/extsupport.php?extension=GL_EXT_paletted_texture
you can use the GL_EXT_paletted_texture extension to specify a conversion between an index and a specific RGBA value. Think about the old 2d technique of palette shift to animate a fire or a waterfall. But with this one, you can have much more indices than 256, it depends on the hardware.

Good luck !

[This message has been edited by ZbuffeR (edited 01-18-2004).]