On the left is what we have now, and on the right what we are trying to achieve. Currently, the line is in one solid color with transparency.
Should we draw a pattern image as an overlay above or brush image should be already with such pattern?
Could you please advice a direction on where to look and what to try?
Brush image that is used is on the left, and watercolor pattern that possibly could be used is on the right.
The following code is used to draw a line with brush texture using the stencil buffer to avoid textures transparency overlap:
glClear(GL_STENCIL_BUFFER_BIT.gluint)
glEnable(GL_STENCIL_TEST.gluint)
glStencilOp(GL_KEEP.gluint, GL_KEEP.gluint, GL_REPLACE.gluint)
glStencilFunc(GL_NOTEQUAL.gluint, 1, 1)
glStencilMask(1)
glDrawArrays(GL_POINTS.gluint, 0, count.int32)
glDisable(GL_STENCIL_TEST.gluint)
Related
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.
I have a texture and I want to draw it to a FrameBufferObject. The texture has transparent areas. I would like the following:
For all transparent pixels, let them be drawn transparent in the FrameBufferObject.
For all non-transparent pixels, let them be drawn using a color of my choosing, ie pure red (ignore their actual rgb value)
I've tried Batch.setColor(red) before drawing the texture, but that just tints it - I want all non-transparent pixels to be drawn pure red.
I am also trying to figure out how to achieve this in just opengl directly, looks like there may be a way to do this with blending, which can then be related back to gdx.
Thanks
You need to write a shader and the shader is the OpenGL program that renders the texture. So your shader would render transparency without change and all else would the color of your own choosing.
The following link has libgdx shaders for palette swapping i.e. direct reassignment of color at render, which you can easily adapt for single color and transparency.
https://www.javaer101.com/en/article/12241616.html
I'm creating a piece of code that will allow my client to zoom into blueprints like the one below, and clip into them, essentially creating an interactive cross section. that's simple enough, by just setting the near plane to a value higher than 0, but I'd like to know if there is a way to apply the crosshatching pattern that you see below on the areas that are clipped. On top of that, is there a way to apply a border around the area that is clipped, creating an outline? I know there is clipping in three js which uses planes, but I'd like to know if it is possible to apply a stencil to the near clipping plane for a camera, and if so, how is it done?
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.
I have started learning CANVAS. After i started drawing some basic shapes, i wanted to make some modifications to them. For example, I am confused of how to modify length and width of rectangle. Should i have to clear the canvas and redraw or can i capture the object of that rectangle like the objects in java script.
The canvas is a raster graphics surface. modifying length and width of a rectangle is a vector action. It is possible to scale a raster, but losses in quality can/will occur. You can use vector graphics in the form of SVG. But if it is only a rectangle, use a div with a border overlay-ed on your canvas.