在GLPaint中使用画笔擦除

din*_*esh 8 iphone

作为修改的一部分GLPaint,我试图添加擦除功能,用户可以选择橡皮擦按钮并擦除绘制区域就像绘画一样.

我正在尝试在"renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end"方法中有一个条件语句,以便我可以检查笔画是用于绘画还是擦除.

对于擦除,我不知道如何使用" start"和" end"参数进行擦除.在OpenGL中是否有任何方法调用glClear()接受这两个参数并擦除?

任何指针都会非常有用.谢谢.

zlo*_*log 10

使用GLPaint中的画笔擦除一样,您可以重复使用

- (void)renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end 
Run Code Online (Sandbox Code Playgroud)

具有以下条件的方法:

if (isEraserBrushType) {
    glBlendFunc(GL_ONE, GL_ZERO);
    glColor4f(0, 0, 0, 0.0);
} else {
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    [self setBrushColorWithRed:brushColourRed green:brushColourGreen blue:brushColourBlue];
}
Run Code Online (Sandbox Code Playgroud)

代码上方:

// Render the vertex array
glVertexPointer(2, GL_FLOAT, 0, eraseBuffer);
glDrawArrays(GL_POINTS, 0, vertexCount);
Run Code Online (Sandbox Code Playgroud)

注意,你需要实现isEraserBrushType,并以某种方式存储brushColourRed,brushColourGreen和brushColourBlue.

  • 刚刚发现这篇文章:http://stackoverflow.com/questions/4074955/blending-a-texture-to-erase-alpha-values-softly-with-opengl使用`glBlendFunc(GL_ZERO,GL_ONE_MINUS_SRC_ALPHA)`似乎做的伎俩. (4认同)