OpenGL es 2.0 blend issue - opengl-es

Now I learning OpenGL ES 2.0 with iOS and try to develop the drawing functions in iPhone.
I have success to draw a line art image and live drawing with finger, thanks to GLPaint.
Live drawing can covered the line art image, but I want the line art drawing without cover the black line.
img This is now I've done with drawing.
Is there any good blend method to do that? Thank you.

I finally done with this issue.
It's simple to use glBlendFunc:
glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
The point is
First parameter is destination color (background color), second is source color.
For default, glBlendEquation is set to GL_FUNC_ADD; if you want to do something different, please remember to change with different case.
In this issue, we don't need to change it, cause we need blend background color with brush color, and black color always cover any color when add two of them.
Make sure set "glEnable(GL_BLEND)" after draw background image.
My mistake is, setting glEnable(GL_BLEND) with compile brush shader, and draw after set all shaders.

Related

HTML5 canvas - make a mono mask efficiently without antialiasing

I am using pixel colour inspection to detect collisions. I know there are other ways to achieve this but this is my use case.
I draw a shape cloned from the main canvas on to a second canvas switching the fill and stroke colours to pur black. I then use getImageData() to get an array of pixel colours and inspect them - if I see black I have a collision with something.
However, some pixels are shades of grey because the second canvas is applying antialiasing to the shape. I want only black or transparent pixels.
How can I get the second canvas to be composed of either transparent or black only?
I have achieved this long in the past with Windows GDI via compositing/xor combinations etc. However, GDI did not always apply antialiasing. I guess the answer lies in globalCompositeOperation or filter but I cannot see what settings/filters or sequence to apply.
I appreciate I have not provided sample code but I am hoping that someone can throw me a bone and I'll work up a snippet here which might become a standard cut & paste for posterity from that.

Libgdx | Set black color to everything outside of circle

How can I set a black color to the whole screen, excluding a shaperenderer circle? The circle is basically my game world, anything that leaves it shouldn't be visible. Is there some way to create a reverse circle pixmap (eg..A circle, but inverted) to overlay everything except for the circle game area? Or maybe a way to clear the screen, excluding parts? Thanks!
You could try the approach you mentioned in the comments. Using a black image with a circular hole in it. Then have each assigned to a different camera much in the same way you would set up a HUD in libgdx.
You might want to take a look at shaders, this approach is really flexible and lets you even control how rapid the transition is. Just the basics of GLSL should be sufficient.
https://www.youtube.com/watch?v=caQZKeAYgD8 Here's a decent tutorial.

Blending two sprites in OpenGL ES without affecting background

Basically what I want to achieve is a sprite highlight animation effect as displayed below.
The idea is that the white-translucent gradient sprite moves on top of the other sprite (left-to-right), using a blend mode like Overlay (Photoshop). The difficult part is that the top gradient sprite should only be drawn on the visible pixels of the sprite underneath. The other part of the gradient overlay should be discarded to not affect the background or other sprites underneath (like on the image to the far right).
Is it possible to achieve that effect with a clever combination of OpenGL blend modes and how, or would I have to create a custom shader to combine these sprites?
Background: I'm using libgdx with OpenGL ES 2.0 and the app runs on Desktop, Android and iOS.
There arÄ™ many ways to do it. The simplest one:
You should render button and hilight in a single pass. In fragment shader, after sampling button texture and hilight texture calc the output color as for blending (could be mix(c1,c2,c2.a)) and alpha as button texture alpha only. Of course enable blending in usual way: (srcalpha,1-srcalpha)

Animate Sprite using color in top to bottom effect

How to spread color Top to Bottom using CCTintTo method in sprite.
Because i am using CCTintTo method to spread color in sprite. But i want to look like spreading color in top to bottom.
What to do for this types of animation.
Thanks in advance.
If you are using cocos2d 2.0+, you could write a shader to do this, and set the shaderProgram property of the sprite. Not that hard, follow the examples in the distribution. My first shader took me .5 work days to get to work, and maybe another .5 workday to properly integrate that technique properly in my overall software architecture. g'luck :).
Look here for an introduction to shaders, play with it in a side project until you are comfortable to integrate in your main trunk.
That's not possible with color tinting. Changing a node's color property or using the tint actions will only tint the entire sprite with a single color, there will be no gradient.
You would have to custom draw the sprite and apply/adapt the gradient rendering code from CCLayerGradient.
Yes CCLayerGradient is what you are looking for.By the way what technique you are using for coloring.If you are using CGContextSetRGBFillColor method to fill the sprite color then it would be tricky but if you are using images to fill color then nice sequence of images plist can be used to produce animation which will give you the exact effect you are looking for.
Take the sequence of images and animate them using CCSpriteBatchNode otherwise if you want to use RGB colors to fill sprite then you have to look for gradient effect.

LibGDX - Sprites to texture using FBO

I am working on a simple painting app using LibGDX, and I am having trouble getting it to "paint" properly with the setup I am using. The way I am trying to do this is to draw with sprites, and add these individual sprites into a background texture, using LibGDX's FBO commands, when it is appropriate.
The problem I am having is something relating to blending, in that when the sprites are added to this texture that I am building, any transparent pixels of the sprite that are on top of pixels that have been drawn to previous will be brightened up substantially, which obviously doesn't look very good. The following is what the result looks like, using a circle with a green>red gradient as the "brush". The top row is part of the background texture now, while the bottom one is still in its purely sprite drawn form.
http://i238.photobucket.com/albums/ff307/Muriako/hmm.png
Basically, the transparent areas of each sprite are brightening anything below them, and I need to make them completely transparent. I have messed around with many different blending mode combinations and couldn't find one that was any better. GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA for example did not have this problem, but instead the transparent pixels of each sprite seem to be lowered in alpha and even take on some of the color from the layer below, which seemed even more annoying.
I will be happy to post any code snippets on request, but my code has become a bit of mess since I started trying to fix these problems, so I would rather only put up the necessary bits as necessary.
What order are you drawing the sprites in? Alpha blending only works with respect to pixels already in the target, so you have to draw all alpha-containing things (and everything "behind" them) in Z order to get the right result. I'm using .glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

Resources