English 中文(简体)
油漆用具,在开放式GLES中采用推土法
原标题:Paint app, using framebuffer to render texture in OpenGL ES

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?

最佳回答

如何用线(没有碎.):简单地使用深度试验(清晰的深度缓冲,对L_NOT_EQUAL的深度 f,或将其保留在GL_LESS上),以避免把同一位置上两度。 然而,这不会带来更为复杂的rush忙。

你的法典有若干主要缺陷。 首先,如果你想向使用FBO的传票,你需要在你向缓冲站做任何事之前,打上冰川。 因此,在白 touch的行动顺序如下:

glGenRenderbuffersOES(1, &brushFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER_OES, brushFramebuffer);
// creates FBO

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);
// creates and attaches RB for depth

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, bufferTexture, 0);
// attaches texture to render to. now we re ready.

其次,你不把 gl光2D()引向来,这将会消除迄今为止对案文所做的一切。 叫 gl冰川(GL_TEXance_2D, GL_TEXpoli_MIN_FILTER, GL_LINEAR);但是,你最好能把这条线移到你制造缓冲创伤的那部分。 为了停止推 frame,有人简单说:

glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);

文本载有在FBO积极运行期间所展示的形象,并转回屏幕(申请表)。

现在,由于你正在利用ture,你需要:

glBindTexture(GL_TEXTURE_2D, bufferTexture);

之后,你刚刚完成了充分筛选:

CGFloat vertices[] = {0, 0,
                      backingWidth, 0,
                      backingWidth, backingHeight,
                      0, backingHeight};
CGFloat texCoords[] = {0, 0,
                      1, 0,
                      1, 1,
                      0, 1,};
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
glDrawArrays(GL_QUADS, 0, 4);

......

在LineFromPoint()中,不需要打电话。

glBindFramebufferOES(GL_FRAMEBUFFER_OES, brushFramebuffer);

因为它已受影响。 但是,它赢得了一定的伤害。

还有一件事——你们应当确保,光顾、触及和触动真正地来到这里。 我不敢肯定这一点。

问题回答

暂无回答




相关问题
Java Updating Small Circles

I need to display a large number (500+) of small circles on a form to simulate LEDs. However, these circles need to be quite small, around 8 or 9 pixels diameter. So far, in my testing, I ve put ...

JMenuBar disappears when I add paint method

Im trying to use the following code to eventually make a game. The code, as shown below, works. import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame implements ...

Mixing two RGB color vectors to get resultant

I am trying to mix two source RGB vectors to create a third "resultant vector" that is an intuitive mix of the first two. Ideally, I would be able to emulate "real paint mixing characteristics", but ...

Paint like Feature in Web.Application?

i want to implement Ms Paint like feature in my web application in c# asp.net. like cropping coloring zooming ,color picker etc . Please tell me is there any pre build tools or application for it.Any ...

DataGridView CellFormatting event preventing form painting

I am using C#, Winforms, and .Net 3.5 My form has a custom DataGridView (double-buffered to prevent flickering during my cellformatting events, as seen here). When I perform a database search, I bind ...

Delphi Form Painting Black Flash When Restoring

When I minimize and restore my Delphi application, the window contents flash a horrible black before (re)painting on Vista/Win7. This can also be seen with the Delphi 2007 IDE - the Object Inspector, ...

热门标签