glDrawArrays(GL_POINTS,0 4)不会在iOS 5.0和openGL ES 2.0中绘制点

时间:2012-03-12 16:32:08

标签: ios opengl-es-2.0 points

我有一个简单的OpenGL ES 2.0代码来绘制点。这是VAO设置:

    static const GLfloat squareVertices[] = {
        -0.5f, -0.5f, -1.0f,
        0.5f, -0.5f, -1.0f,
        0.5f,  0.5f, -1.0f,
        -0.5f, 0.5f,  -1.0f
    };

    static const GLfloat squareColors[] = {
        1.0f, 0.0f, 0.0f, 1.0f,
        0.0f, 1.0f, 0.0f, 1.0f,
        0.0f, 0.0f, 1.0f, 1.0f,
        1.0f, 0.0f, 1.0f, 1.0f
    };
    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);

    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(squareVertices), squareVertices, GL_STATIC_DRAW);

    glEnableVertexAttribArray(ATTRIB_VERTEX);
    glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, 0);

    glGenBuffers(1, &_colorP_VBO);
    glBindBuffer(GL_ARRAY_BUFFER, _colorP_VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(squareColors), squareColors, GL_STATIC_DRAW);

    glEnableVertexAttribArray(ATTRIB_COLOR);
    glVertexAttribPointer(ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, 0);
    glBindVertexArrayOES(0);

这里是渲染代码:

    [glView setDisplayFramebuffer:glView.viewFrameBuffer];

    glUseProgram(simpleShaderProgram);
    glBindVertexArrayOES(_vertexArray);

//  glLineWidth(5.0f);
//      glDrawArrays(GL_LINE_LOOP, 0, 4);
//      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//  glEnable(GL_POINT_SMOOTH);

    glPointSize(25.0f);
    glDrawArrays(GL_POINTS, 0, 4);

    glBindVertexArrayOES(0);

    glUseProgram(0);

    glBindFramebuffer(GL_FRAMEBUFFER, 0); //unbind the FBO  
    [glView presentFramebuffer:glView.viewFrameBuffer];

当我使用GL_LINE_LOOP或GL_TRIANGLE_FAN时,它会在屏幕上绘制彩色方块。但是,当我使用GL_POINTS时,渲染器不会绘制顶点,而屏幕是空白的。 如果有人让我知道我错过了什么,我感激不尽。 感谢

以下是我的顶点和片段着色器:

attribute vec4 position;
attribute vec4 v_color;

varying vec4 colorVarying;


void main()
{
    colorVarying = v_color;
    gl_Position =  position;

}

------------------------------------------------
precision mediump float;
varying vec4 colorVarying;


void main()
{
    gl_FragColor = colorVarying;
}

1 个答案:

答案 0 :(得分:4)

您正在使用ES 2.0,因此glPointSize()调用可能无法执行任何操作。应使用gl_PointSize内置输出变量在着色器内设置磅值。