0

I fallowed @Stefan Monov tutorial in this question. And everything works, but I need to make it working with my brush. I need to do so:

// Next, we want a blendfunc that doesn't change the color of any pixels,
// but rather replaces the framebuffer alpha values with values based
// on the whiteness of the mask. In other words, if a pixel is white in the mask,
// then the corresponding framebuffer pixel's alpha will be set to 1.
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
// Now "draw" the mask (again, this doesn't produce a visible result, it just
// changes the alpha values in the framebuffer)
drawQuad(maskTexture);

would be not a static texture, but dynamic shape. I mean, i'm trying to implement brush witch is doing such a thing that is written by @Stefan Monov. So I need that this place could be implemented in other - (void) function, so that it could be called, when coordinates changes (when user draws). I tried a variety of ways to change the sequence of your code, but it does not work correctly then. Now my bursh code is:

glEnable(GL_BLEND);
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
glPointSize(100);
glBegin(GL_POINTS);
glColorMask(1.0,1.0,1.0, 1.0);
glVertex2f(loc.x, loc.y);
glEnd();
glDisable(GL_BLEND);

It is called when mouse is dragged. "loc" is dragged mouse coordinates. Afcourse its not working now at all, because of blendFunc and code's sequence. When I leave sequence as @Stefan Monov described, it works, but it draws one point and drags it when mouse is dragged. Becouse after drawing point, other textures is being redrawed too. Any, at least similar, solution for it?


To make it more clear i'll show how I want my APP to work.

Here is the original code:

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
drawQuad(backgroundTexture);

glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
drawQuad(maskTexture);

glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
drawQuad(foregroundTexture);

Now its working like this:

  1. Draws background
  2. Draws mask
  3. Draws foreground

I need it to work like this:

  1. Draws bacground
  2. Draws foreground
  3. Draws mask

But if i change the order of drawings it stops working. Ignores mask.

Expected result foto: enter image description here

Community
  • 1
  • 1
hockeyman
  • 1,141
  • 6
  • 27
  • 57
  • What is your app trying to do? Can you post a mockup image of what kind of result you're trying to get? – Tim Jul 03 '12 at 16:33
  • Explain what I'm looking at? Is that a static mask, or for some kind of paint application? – Tim Jul 03 '12 at 17:35
  • Its paint application. Where image is colored, there was a brush stroke. Sorry for my bad english. – hockeyman Jul 03 '12 at 17:58
  • Have you considered looking at the stencil buffer for this? I think it would be more appropriate than trying to use blending. – Tim Jul 03 '12 at 18:21
  • I didin't tried this. Just masking looked simplier solution. And I guess i'm getting the idea how to fix my issue. I just need to draw mouse coordinates to vertex array and every time when value is added to vertex array i should redraw my mask texture. Becouse now everything works but my brush draws one colored point, and in mousedrag it just drags that colored point with mouse. So now i will try this solution. Later on, if my solution will not work, i will try yours. Thank you :) – hockeyman Jul 03 '12 at 18:52

1 Answers1

0

Your attempt to draw the mask last makes no sense really.

Drawing the mask only modifies what's in the alpha channel, and the alpha channel itself is not visible in any way in the final image.

The only use of the mask is to modify what's drawn after it.

Tim
  • 35,413
  • 11
  • 95
  • 121