I am trying to extend the opengl Texture2d so it becomes more useful. What I want to achieve is to pass in custom Position, Rotation, Scale and Color in the drawAtPoint function. The position, rotation and scale part was easy, but I can't make the color multiply or blend with the texture. This is how the code looks like now.
I may be wrong, but I did some testing and found that switching these modes was much too costly to do on a texture by texture basis when you're making more than a couple things transparent. To get around this I draw transparent textures in groups like shown below:
Code:
Excerpt from renderScene():
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0,1.0,1.0,0.5) // This line sets the alpha for the group to 0.5
** Draw the textures ([texture drawAtPoint/drawInRect], etc.)
glColor4f(1.0,1.0,1.0,1.0)
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
This will get you nice transparent textures with no artifacts
Thanks. This works (as does the previous code) but I find that areas that are partially transparent don't show up. For instance consider I have a png of a moon with some glow around it; if I use this method the glow around the moon doesnt show up, even when the alpha is set at 1.0.
So you have a png with some built-in transparancy, correct? And that transparency doesn't work even if you have the alpha set to 1? Then I'd think the problem is with your PNG, and not your draw method. At 1, the PNG should be drawn as opaque as possible. Have you recently added the glow? Try running a Clean and rebuilding.
As far as I can tell the PNG is just dandy; basically it is a 256 x 256 square; in the center of it is about a 200x200 moon (opaque) surrounded by some glowness (partial alpha) which fades out to completely transparent as it goes further out. If I use this same graphic in an imageView or whatnot it works fine; confused.
I'm confused as to what you're trying to do, then. This thread was about making a texture that is opaque transparent.
Are you saying:
1) That if you just try to display your stock PNG that the glowing part that's affected by the alpha channel is missing? or
2) When you try to apply a constant alpha to your PNG, the glowing part disappears?
It probably has to do with your GL parameters. I have both textures that I'm applying a constant alpha to as well as textures with alpha shadows that I'm applying additional alpha to, and both work correctly with the stock Texture2D (when used with the code I posted).
Its really not that complicated. I have the above graphic that I was talking about right? Now, i want to use that graphic in a situation where the whole screen is fading in; to do the fade in I was using the openGL blending modes; but when it fades in; the glow on the moon is gone: problem.
Maybe I can just get around this by having a black texture over the image in question and fading that out (as opposed to fading the image in).... still curious about this though; any thoughts?
I think everything is set up in the proper way; and on the device the "glow" does show up... a little bit; its just not nearly as vibrant as it should be.
Hmm... I don't recall if my shadow seemed darker than usual, I just checked to make sure it was there. May it's doing some kind of multiplication of the alphas that's unexpected.
Have you tried changing your clear color? I recall that having some effect on how transparency is generated. That's really the only thing I can think of.
I do think your workaround will be fine. I use a 1x1 black texture I stretch and apply an alpha to to darken the background at some points, though there is probably a better way to do it.
Yeah, thats a good idea to save some memory;and yeah I remember someone else saying something about the clear color; I'll mess around with it. It's not critical but I'd like to figure it out if possible. Thanks for the suggestions.
(assume the other arrays (vertex, texcoord) are set up as normal)
I *believe* that I could equally do this without applying per-vertex alpha by just doing glColor4f(alpha, alpha, alpha, alpha) once, per other notes in this list. But I got it working this way, so I've stopped here for now.
Here's the effect I was after. I have a background texture. I have an overlay texture with an alpha channel in it. When drawing the overlay texture, and alpha was passed in as 0.0f, I want the overlay texture to "be ignored". When it's at 1.0f, I wanted the full value of the overlay color to be rendered on top of the background.
Tip: I originally passed in color values of 1.0, 1.0, 1.0, alpha (RGBA), and I was getting what I'd call "overbrightening" when alpha was zero. Turns out this was because GL_MODULATE was still taking into account the vertex color (full bright white) in the calculation. If I make the RGB value be greyscale, at the same intensity as the alpha, it works as I expect. When alpha is zero, GL_MODULATE sees a vertex color of black, and I don't see overbrightening.
Hope this explanation was helpful for any of your situations.
(assume the other arrays (vertex, texcoord) are set up as normal)
I *believe* that I could equally do this without applying per-vertex alpha by just doing glColor4f(alpha, alpha, alpha, alpha) once, per other notes in this list. But I got it working this way, so I've stopped here for now.
Here's the effect I was after. I have a background texture. I have an overlay texture with an alpha channel in it. When drawing the overlay texture, and alpha was passed in as 0.0f, I want the overlay texture to "be ignored". When it's at 1.0f, I wanted the full value of the overlay color to be rendered on top of the background.
Tip: I originally passed in color values of 1.0, 1.0, 1.0, alpha (RGBA), and I was getting what I'd call "overbrightening" when alpha was zero. Turns out this was because GL_MODULATE was still taking into account the vertex color (full bright white) in the calculation. If I make the RGB value be greyscale, at the same intensity as the alpha, it works as I expect. When alpha is zero, GL_MODULATE sees a vertex color of black, and I don't see overbrightening.
Hope this explanation was helpful for any of your situations.
hello,
i have one problem,can you help me?
i have change GLPaint Application.
i have set two overlapping image, when i draw line using finger on top of the image that part should be erase (and underling image should be appear).
i am very frustrate about this issue, please help me