I m 试图根据果树苗进行简单的油漆应用。 为了打上一条线,GLPaint用粗体字标出一系列点。 随着开放式GL的bl化,与甲型六氯环己烷相比,该线的每一点都与以前的点混在一起。 我想避免这种情况。 例如,你将红色颜色 set为粉碎和甲型,为0.5,抽出一条线,所有线为单体col——与甲型0.5相重复,没有自发通道。 我可以清楚地解释,但我希望大家理解我)
因此,第一个问题是我如何做到这一点?
我决定用目前的行文进行校正,不作混淆,然后将目前的形象翻开。 该守则是:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGRect bounds = [mainView bounds];
UITouch* touch = [[event touchesForView:mainView] anyObject];
firstTouch = YES; location = [touch locationInView:mainView];
location.y = bounds.size.height - location.y;
// Offscreen buffer
glGenRenderbuffersOES(1, &brushFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER_OES, brushFramebuffer);
glGenRenderbuffers(1, &brushDepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, brushDepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rushDepthBuffer);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE) {
NSLog(@"failed to make complete framebuffer object %x", status);
return;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGRect bounds = [mainView bounds];
UITouch* touch = [[event touchesForView:mainView] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch locationInView:mainView];
previousLocation.y = bounds.size.height - previousLocation.y;
}
else {
location = [touch locationInView:mainView];
location.y = bounds.size.height - location.y;
previousLocation = [touch previousLocationInView:mainView];
previousLocation.y = bounds.size.height - previousLocation.y;
}
[self renderLineFromPoint:previousLocation toPoint:location];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGRect bounds = [mainView bounds];
UITouch* touch = [[event touchesForView:mainView] anyObject];
if (firstTouch) {
firstTouch = NO;
previousLocation = [touch previousLocationInView:mainView];
previousLocation.y = bounds.size.height - previousLocation.y;
[self renderLineFromPoint:previousLocation toPoint:location];
}
// getting texture from buffer
glBindTexture(GL_TEXTURE_2D, bufferTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 768, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, bufferTexture, 0);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
// drawing texture to image
CGFloat vertices[] = {backingWidth/2, backingHeight/2};
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_POINTS, 0, 1);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
}
- (void) renderLineFromPoint:(CGPoint)start toPoint:(CGPoint)end {
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, brushFramebuffer);
glBindTexture(GL_TEXTURE_2D, brushTexture);
/// .... then drawing a line from "start" to "end"
}
The second question is: this code draws only draws brush texture to the center of screen, what am I doing wrong?