PDA

View Full Version : how to draw "Masked" 2D image with fade-in/out



mdive
06-20-2003, 05:29 PM
Hello.
To draw "masked" 2D image, I'm using next code:
(I study from next web site : http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=20)
------------------------------
//draw mask
glBlendFunc(GL_DST_COLOR, GL_ZERO);
glBindTexture(GL_TEXTURE_2D, mask_id); //bind mask to current texture
glCallList(5); //draw textured quad

//draw image
glBlendFunc(GL_ONE, GL_ONE);
glBindTexture(GL_TEXTURE_2D, image_id); //bind image to current texture
glCallList(5); //draw textured quad
---------------
above code draw no fade-in/out 2D Image.

By the way, I want to draw fade-in/out "masked" 2D image. How can I set glBlendFunc?

I tryed next code, but I don't get fade-in/out 2D masked iamge.
-------------------------
//draw mask
glBlendFunc(GL_DST_COLOR, GL_ZERO);
glBindTexture(GL_TEXTURE_2D, mask_id);
glCallList(5);

//draw image
//glBlendFunc(GL_ONE, GL_ONE); //comment out
glBlendFunc(GL_SRC_ALPHA, GL_ONE); //<-add
glBindTexture(GL_TEXTURE_2D, image_id);
glColor4f(1.0f, 1.0f, 1.0f, alpha); //<- set alpha factor to quad for 2D image.
glCallList(5);
-------------------------------
I should guess that If mask-image's black color can fade-in, we can get fade-in/out masked 2D image.

I want to understand how we set glBlendFunc in this case, to get fade-in/out Masked 2D images.

If you have any suggestion, please help me.
sorry, my broken English.


[This message has been edited by mdive (edited 06-21-2003).]

jwatte
06-21-2003, 10:24 AM
Your post doesn't tell us at all what specific effect you want.

If you want to draw an image that fades in where alpha is higher, you should set blend function to GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, and draw the image. Make sure your coverage mask is in the alpha channel (this means you have to call glTexImage and glTexEnv correctly).

If you want to mask one image with another image, you have to bind the mask to one of the texture units, and the image to the other, and make sure the mask is an ALPHA or LUMINANCE texture, and set your TexEnv (and possibly COMBINE func/mode) correctly.

Read up on texture environment application in the GL spec (downloadable as a PDF from the front of this web site).

mdive
06-21-2003, 11:08 PM
Thank you very much for your reply.
I want to draw image like this.
http://www.geocities.com/screen_314/image.html

Above image show no fade-in/out.
But I want to draw 2d logo image with fade-in/out in OpenGL.

I have not been understood about TexEnv concept and texture environment application in the GL spec yet.

I want to study texture environment concept from now on.

[This message has been edited by mdive (edited 06-22-2003).]

[This message has been edited by mdive (edited 06-22-2003).]

tfpsly
06-23-2003, 12:47 AM
Look for the gl_constant_color and glBlendColor( R,G,B,A ). You can use that to specify a color which components fade from 0 to 1 and use that for your fading.

Another way would be to use multitexturing, to multiply the logo texture alpha by a color (1,1,1,fade) That way would preserve your texture transparency.

mdive
08-01-2003, 04:22 PM
Thank you very much for your replay.
(sorry, very very late response...,
I triped to sea for a while:-P)

After I heard your advice, I tried to get the fadein/out masked image by 32 bit RGBA TGA format file, and I could get one.

I'm very glad to hear your advice, and I got good inspiration.

My knowledge of alpha blending is still immature. I'm going to study more.

Sorry, my broken English.
Thanks.