a texture coloring question
Hi guys,
I have two textures like below:
the first one(a 7*19 texture with a triangle inside):
0000000000000000000
0000000000001000000
0000000000111000000
0000000011111100000
0000001111111110000
0000111111111111000
0011111111111111100
the second one(a 7*19 texture with a polygon inside):
0000010000000000000
0000111110000000000
0001111111100000000
0001111111111000000
0011111111110000000
0111111111000000000
1111111100000000000
I am gonna map these two textures into framebuffer. And I will
dedicate the blue color to the first one and red color to the second
one. So I have to use the GL_MODULATE so that I can use the glcolor3f
to decide the color of texture before the scan-conversion(Inside
texture buffer, these two textures are just black(0)&white(1)).
Here is what I want. In the overlap area, if texture1 is black and texture2 is black, the last color should be black. In the place that one of the texture is not black, another one is black, the last value remains as the nonblack value. And if both texture1 and texture2 have nonblack color, the upper one defines the last color.
The combination of "GL_ONE,GL_ONE_MINUS_SRC_ALPHA " is not working. I tried other combinations, no one works.
I think maybe the simple blending function can''t solve this problem. Maybe something in the glextension set can do the work.
Any help is appreciated, thanks
kevin
Seems I have to use the alpha channel. But how. There is no order for mapping the texture. And the black should be transparent. All other colors is totally opaque. The higher one overwrite the lower one.
please help,
Jian
please help,
Jian
For each image you load in, use the pixel data you''re loading for both the colour and alpha information for that texture. That way areas that are black are assigned an alpha value of 0 and get masked out, while areas that are filled are assigned an alpha value of 1. Once that''s done, you should just be able to blend the two textures together.
Just a warning: most OpenGL blend modes are based on alpha. But on the plus side, if you want to blend using just your colour you could do something like this:
glBlendFunc(GL_SRC_COLOR, GL_DEST_COLOR);
or some combination of GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DEST_COLOR, GL_ONE_MINUS_DEST_COLOR!
glBlendFunc(GL_SRC_COLOR, GL_DEST_COLOR);
or some combination of GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DEST_COLOR, GL_ONE_MINUS_DEST_COLOR!
thanks so much for your guys'' reply.
I tried all the combinations, but no effect is what I want.
I just want black part of texture is transparent but color part(no matter what color it is) is totally opaque. Seems I can''t avoid the alpha.
My confusion is:
1 When I use RGB in texture, the alpha is default 1.0 for all pixel in texture. But why the black part still be transparent?
2. When I use color3f(1.0, 0.0, 1.0) to dedicate the color of texture(before the glBegin(GL_QUADS)), can this command change the alpha of my texture? (I am using modulate)
These are pretty newbie questions, thanks in advance
Kevin
I tried all the combinations, but no effect is what I want.
I just want black part of texture is transparent but color part(no matter what color it is) is totally opaque. Seems I can''t avoid the alpha.
My confusion is:
1 When I use RGB in texture, the alpha is default 1.0 for all pixel in texture. But why the black part still be transparent?
2. When I use color3f(1.0, 0.0, 1.0) to dedicate the color of texture(before the glBegin(GL_QUADS)), can this command change the alpha of my texture? (I am using modulate)
These are pretty newbie questions, thanks in advance
Kevin
so basically, you do not want the black to show up, just the colored parts of the texture.
glColor4f(R, G, B, Alpha) will only set the alpha for the whole image, so thats not what you want.
You DO need an alpha channel to do what you want without using fragment shaders.
glBlendFunc(GL_ONE, GL_ONE) would sort of work, but it would also add the 2 colors together, that isnt what you want.
How are you loading your textures?
glColor4f(R, G, B, Alpha) will only set the alpha for the whole image, so thats not what you want.
You DO need an alpha channel to do what you want without using fragment shaders.
glBlendFunc(GL_ONE, GL_ONE) would sort of work, but it would also add the 2 colors together, that isnt what you want.
How are you loading your textures?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement