Draw a curved line from an arc edge

后端 未结 2 1421
面向向阳花
面向向阳花 2021-01-23 15:54

Here\'s the screenshot of what I am doing. Currently, I\'m stuck from drawing a curved borders into this rectangle.

<script

2条回答
  •  礼貌的吻别
    2021-01-23 16:18

    You expressed an interest in seeing how this could be solved using the stencil buffer yesterday, so I am following up with some basic pseudo-code.

    glClearStencil (0x0);
    glClear        (GL_STENCIL_BUFFER_BIT);
    
    glEnable       (GL_STENCIL_TEST);
    glStencilFunc  (GL_ALWAYS, 0x0, 0x0);
    
    // Add 1 to stencil buffer at every location the object to be bordered is visible
    glStencilOp    (GL_KEEP, GL_KEEP, GL_INCR);
    
    // Draw your grey object
    
    // Only draw the red border where the grey object was never drawn (stencil = 0x0)
    glStencilFunc  (GL_EQUAL, 0x0, 0xff);
    
    // Draw your red quarter circles
    
    glDisable     (GL_STENCIL_TEST);
    

    Clearing the stencil buffer everytime you draw your outlined object is probably overkill. If you opt to clear the stencil buffer once per-frame instead, you can do some pretty interesting things. For instance, if you drew the outlines as a separate pass after all non-outlined shapes are drawn you could use this stencil buffer setup to outline the union (instead of including the intersection of objects as part of the drawn outline) of any overlapping objects.. this would allow you to construct more complicated shapes from your simple rounded rectangles.

    Of course for this to work, your pixel format must have a stencil buffer. I will have to leave that part up to you, because the process of setting that up is implementation specific.

提交回复
热议问题