Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Blending or painting transparent to texture

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41

    Blending or painting transparent to texture

    So I need to draw transparent brush strokes to OpenGL texture, to use it as mask later on. I have brush image (black square with transparent circle). And I need to draw brush stroke of that transparent part of brush texture to other opengl texture. I know how to do it directly drawing and blending, but now firstly I need to draw to texture. I was using code like this for that what I want to achieve. And it was working. But how can I firstly draw mask to texture (i know how to draw something to texture using FBO, but how to draw nice transparent brush strokes to it and make texture for example fully black, with only brushstrokes transparent?), and only then use this texture as mask. So if now I am acting like that:

    Code :
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ZERO);
    //draw background
     
    glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
    //Draw vertexarray for brush strokes.
     
    glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
    //draw foreground

    I want to act like that:

    Code :
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, someFramebufferForBrushStroke);
    //draw vertexarray for brush strokes to texture
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
     
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ZERO);
    //draw background
     
    glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ZERO);
    //Draw mask quad texture (texture witch is binded as GL_COLOR_ATTACHMENT to my frame buffer
     
    glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
    //draw foreground

    Now I drag mouse, and OpenGL draws textured(my brush texture) quad at every mouse event location.
    I want to: when I drag mouse openGL draws whole vertex array to texture (all these textured quads at mouse location, witch in my current method draws directly to screen), and then uses that texture as mask (draws full size quad).

    Its OK with drawing to texture, but just what blending or something I should use to tell opengl to make transparent parts of texture where in my brush texture is transparent circle and to ignore black square around transparent circle?

  2. #2
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41
    Some visualization (lets say that white color is transparent part, and my mask is black quad with transparent circle in it):

    Now when I render my brushstroke to FBO i get something like that:
    Click image for larger version. 

Name:	Screen Shot 2012-08-10 at 10.05.58 AM.png 
Views:	142 
Size:	5.6 KB 
ID:	853


    And I need result like that:
    Click image for larger version. 

Name:	aaa.png 
Views:	124 
Size:	4.7 KB 
ID:	854

    So I need to ignore black part of mask while drawing it to empty, cleared with black, fbo.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    But how can I firstly draw mask to texture
    You don't need to draw the brush to a texture; just load the data directly with something like glTexImage2D. The pixel data should be of the form RGBA with the alpha used to set your mask.
    Now you can use this texture in your code.

    If you are making the texture via some draw function to a bound texture just make sure you are writing the alpha component as well as the rgb.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •