【问题标题】:GL_LINES drawing erratically (iPad + OpenGL ES1)GL_LINES 绘制不规律(iPad + OpenGL ES1)
【发布时间】:2014-07-15 17:35:05
【问题描述】:

我的 ipad 应用程序出现了一个非常奇怪的故障。这非常简单:我只是使用“touchesMoved”处理程序在两点之间画一条线。因为我希望线条留在屏幕上,所以我没有在我的绘图函数中调用“glClear”,但由于某种原因,有些线条会丢失,而且看起来完全是随机的。更奇怪的是,它在模拟器中完美运行。有没有人知道为什么会这样?我已经包含了我的触摸和绘图例程。

非常感谢!

皮特

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches]; 
    switch ([allTouches count])
    {
        case 1:
        { //Single touch
        } break;
        case 2:
        { //Double Touch
            UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
            CGPoint location1 = [touch1 locationInView: [touch1 view]];
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            CGPoint location2 = [touch2 locationInView: [touch2 view]];

            [self drawLineWithStart:location1 end:location2];
        } break;
        default:
            break;
    }   
}


- (void)drawLineWithStart:(CGPoint)start end:(CGPoint) end
{   
    [EAGLContext setCurrentContext:context];
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

    GLfloat lineVertices[] =
    {
        (start.x/(768.0/2.0)) - 1.0, -1.5 * ((start.y/(1024.0/2.0)) - 1.0),
        (end.x/(768.0/2.0)) - 1.0, -1.5 * ((end.y/(1024.0/2.0)) - 1.0)
    };  

    glDisable(GL_TEXTURE_2D);

    // Render the vertex array
    glVertexPointer(2, GL_FLOAT, 0, lineVertices);
    glDrawArrays(GL_LINE_STRIP, 0, 2);

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

【问题讨论】:

    标签: objective-c ipad opengl-es


    【解决方案1】:

    此代码在没有清除的情况下在双缓冲上下文中执行 presentRenderBuffer。这意味着它绘制到一个缓冲区,呈现它,绘制到另一个缓冲区,呈现它等等。因此,没有一个可见缓冲区拥有所有的线图,并且交换(存在)将显示交替缓冲区中的差异。模拟器双缓冲方案与物理设备不同,这解释了您所看到的差异。

    在数据结构中累积行。每一帧都清除然后画出所有的线。

    【讨论】:

      【解决方案2】:

      根据情况,也可以保留后盾。这将解决您的问题,但会降低您的性能。

      在您的 OpenGLES2DView.m 中将 kEAGLDrawablePropertyRetainedBacking 更改为 YES。它看起来像这样:

              eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                          [NSNumber numberWithBool:YES], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
      

      但重申一下,它会降低性能,但是我想说,如果您正在尝试编写绘图应用程序(从外观上看),它可能就是您正在寻找的东西。由于在绘图应用程序中,重新运行逻辑以重绘每一帧并不是一个好主意,这是一个很好的解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-03-13
        • 2013-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多