I am trying to modify the GLPaint sample from apple to draw a solid line instead of the transparent neon like line in it. I am trying to achieve the touch paint function to look something like a spray paint effect. I tried disabled the glblend but no effect. And also I am trying to make OpenGL to draw on a background image instead of the default black color. Or is it possible to make Open GL to draw on a UIImageView with transparent background ?
in the paintingView.h you will find:
#define kBrushOpacity 1.0 //the opacity of the line
#define kBrushPixelStep 1 // the density the dots
#define kBrushScale 14 //thickens of the line (1 = thickest)
#define kLuminosity 0.5 // the Luminosity. I think that this is what you have to play with
#define kSaturation 1.0 //the Saturation of the line color
changing those parameters will allow you to achieve solid line.
the settings above suppose to give you a thin solid line.
hope it will help.
shani
Related
I am drawing a line using CGContext and color has transparency of 0.7 , Now i want to draw another line with another color with same transparency on that previous line . But i get the second line color as a solid color without any transparency in the part where this both two lines intersect. For first line i am using blend effect clear to draw a transparent line and for the second line i am using blend effect color. Please tell me how to draw these two lines separately so that the second line drawn can have its own separate color .
The default blending mode (kCGBlendModeNormal) should provide the behavior you want in both cases.
I'm working with this excellent example of converting an image to grayscale: Convert Image to B&W problem CGContext - iPhone Dev
However, for my purposes, I would like to have only pure black and pure white left in the image.
It appears that to do so, I need to pass a black and white color space to the recolor method using a call:
CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(/*black and white name*/);
However, I was unable to find the proper iOS color space names. What I found was from Mac, and the "color space names" referenced from the iOS docs does not point anywhere.
How can I properly create a black and white CGColorSpaceRef?
Thank you!
I am not familiar with a black and white only color space but what you can do is calculate the total average RGB value from all the pixels (lets call it totalAvg) and use it as a threshold. Meaning for each pixel if its rgb average is greater than the calculated totalAvg than set it to pure white, otherwise set it to pure black.
I agree it is a bit of more work but thats whay I can think of unless you find the colorspace you are looking for.
You might try creating a gray color space, then creating an indexed color space with two colors (black and white, obviously) and using that.
I am making a custom View where I am plotting a curve. Now I want the background of that curve to be like a graph paper.
shall I use a vertical and horizontal lines Or draw a series of rectangles Or use background image?
currently I am using vertical and horizontal lines but the problem is even when I am setting the thickness of the line to be 1 pixel, It still seems to be thicker and If I reduce the thickness to say 0.5 then the color becomes lighter than what I have set it to.
For this kind of thing, if you don't expect to have to make many, many dynamic changes to the background image, you could just use a carefully-crafted .png. You can even make the thing a single square and then use
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"template"]];
Although, if you're doing plot work, then you may want to draw the lines manually as you are. The answer to your question then is to make the stroke width 1.0 but to draw the lines at the halves: so to draw a vertical line down the 100th x pixel column, move the cursor to (99.5, 0.0) and stroke to (99.5, 480.0). CoreGraphics drawing routines draw your stroke centered on the theoretical line you create, and will antialias to physical pixels as necessary.
I'm trying draw on a white background by reverse engineering GLPaint. I've gone through every combination of kSaturation, kLuminosity and glBlendFunc, AND just about every combination I can think of for brush texture (black on white, white on black, white on trans, alias/no alias, etc), but haven't stumbled upon the desired effect.
The best I've been able to achieve is with a white-on-trans circle, with glBlendFunc (GL_ SRC_ ALPHA, GL_ ONE_ MINUS_ SRC_ ALPHA), but this still gives me a dull colour, and the semi-trans outer bits are interpreted as black (i.e. dull green with black edges, instead of vibrant green with transparent edges). It's as though it still assumes I'm on a black background.
Any advice?
(source: straandlooper.com)
Did you also:
glEnable(GL_BLEND);
?
I believe this is what you want for it to work on White:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Then use a white 'Particle.png' circle that feathers out to transparency (your 'best' example).
This should give in the desired result.
Yup, glEnable(GL_BLEND) is in there.
I've basically started with GLPaint and changed the background to white and the rest of the code is the same. I have to assume that since GLPaint was made with black background, there's some bit of code that is set to blend ideally to black, and I don't know which switch to flip (or, indeed, what switches can be flipped. Heck, what switches even exist).
Here's what's there by default. Lemme know if you see anything awry...
glDisable(GL_DITHER)
glMatrixMode(GL_PROJECTION)
glMatrixMode(GL_MODELVIEW)
glEnable(GL_TEXTURE _2D)
glEnableClientState(GL_VERTEX _ARRAY)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC _ALPHA, GL_ONE _MINUS _SRC _ALPHA)
glEnable(GL_POINT _SPRITE _OES)
glEnable(GL_COLOR _MATERIAL)
I don't mind telling you, I haven't a clue what any of that is.
-kev.
I want to draw with a texture brush, in a color of my choice, on a white background using OpenGLES.
I have a bitmap image which I use CG to load and turn into a texture. This bitmap is mostly black, but has a white circle in the center that I want to use as the "brush". In other words, I want the black part to vanish in the final compositing, but the white part to take on the color that I set using glColor.
The best I can get is with the blend parameters (GL_SRC_ALPHA, GL_ONE) after setting some opaque bright color is a faded color line on a grey (not pure white background). But when I set the background to pure white, the line isn't visible.
At least in the current situation, the black edges of the original texture don't appear. Most other blend combinations I'm trying cause either nothing to show up even on grey, or to see the entire brush including the black edges, which is no good.
Is anyone willing to explain to me how I should set up my texture and/or GL states to make the bright color show through on pure white, without showing the black texture edges at all? This might be a newbie question, but I've tried working through the blend math, and I still just don't understand how the colors are all being factored together.
Here's the image I'm using as the brush:
alt text http://www.coldcoffeeandjuice.com/OpaqueBrush.png
Here's some resulting output, when the background is grey, and the glColor4f is set to (1, 0, 0, 1), eg pure red, and the brush is used on a bunch of consecutive GL_POINTs. Note that what's good about this is that only the white part of the brush image shows the color red-- that's right. The bad parts is that the red which I want to be pure and bright is pale due to being blended with the background (?) and/or the white of the brush (?) so that it washes out entirely if the background is pure white. This uses the blend params as given above (src_alpha, one).
(source: coldcoffeeandjuice.com)
Here's what I want to see, given the pure red color (thanks Paintbrush):
(source: coldcoffeeandjuice.com)
Can anyone help me understand what I'm doing wrong?
Thanks!
Ok, so you're trying to "paint" a given colour (in this case "red") on to a background, using a mask for the brush shape.
You need to do the following before you start rendering the "paint":
First make sure your brush has an alpha channel that corresponds with its shape - that is the alpha channel should look similar to the brush image you posed.
Render with these states set (note space to get around wiki markup):
// Make the current material colour track the current color
glEnable( GL_COLOR_MATERIAL );
// Multiply the texture colour by the material colour.
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// Alpha blend each "dab" of paint onto background
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
See also:
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/colormaterial.html
http://www.khronos.org/opengles/documentation/opengles1_0/html/glTexEnv.html