Tôi nghĩ rằng tôi có thể giải quyết vấn đề này, mặc dù không phải là rất tốt.
Bạn có thể tạo bản sao chức năng mới của "renderLineFromPoint", như thế này;
- (void) drawErase:(CGPoint)start toPoint:(CGPoint)end
{
static GLfloat* eraseBuffer = NULL;
static NSUInteger eraseMax = 64;
NSUInteger vertexCount = 0,
count,
i;
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
// Convert locations from Points to Pixels
CGFloat scale = 1.0;//self.contentScaleFactor;
start.x *= scale;
start.y *= scale;
end.x *= scale;
end.y *= scale;
// Allocate vertex array buffer
if(eraseBuffer == NULL)
eraseBuffer = malloc(eraseMax * 2 * sizeof(GLfloat));
// Add points to the buffer so there are drawing points every X pixels
count = MAX(ceilf(sqrtf((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y))/kBrushPixelStep), 1);
for(i = 0; i < count; ++i) {
if(vertexCount == eraseMax) {
eraseMax = 2 * eraseMax;
eraseBuffer = realloc(eraseBuffer, eraseMax * 2 * sizeof(GLfloat));
}
eraseBuffer[2 * vertexCount + 0] = start.x + (end.x - start.x) * ((GLfloat)i/(GLfloat)count);
eraseBuffer[2 * vertexCount + 1] = start.y + (end.y - start.y) * ((GLfloat)i/(GLfloat)count);
vertexCount += 1;
}
//}
//glEnable(GL_BLEND); // 打开混合
//glDisable(GL_DEPTH_TEST); // 关闭深度测试
//glBlendFunc(GL_SRC_ALPHA, GL_ONE); // 基于源象素alpha通道值的半透明混合函数
//You need set the mixed-mode
glBlendFunc(GL_ONE, GL_ZERO);
//the erase brush color is transparent.
glColor4f(0, 0, 0, 0.0);
// Render the vertex array
glVertexPointer(2, GL_FLOAT, 0, eraseBuffer);
glDrawArrays(GL_POINTS, 0, vertexCount);
// Display the buffer
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
// at last restore the mixed-mode
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
Tiếng Anh của tôi kém. Bạn có hiểu những gì tôi nói không? Hy vọng những điều này có thể giúp bạn.
Có khả thi không? – blacky
vâng, câu trả lời được đưa ra bởi zlog hoạt động trong ứng dụng vẽ của tôi – thgc