OpenGL ES antialiasing with rendering using GL_LINES

418 Views Asked by At

I am struggling to render smooth lines using GL_LINES. I have borrowed the MultisampleConfigChooser from the following link: MultisampleConfigChooser.java

It seemed to find the multisample configuration without any errors. Here is the code I use to render the lines on the screen:

    GLES20.glUseProgram(this.lineDrawProgram);

    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
            mPositionHandle, 2,
            GLES20.GL_FLOAT, false,
            6*4, linesData);

    linesData.position(2);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    GLES20.glVertexAttribPointer(
            mColorHandle, 4,
            GLES20.GL_FLOAT, false,
            6*4, linesData);

    linesData.position(0);

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, matrix, 0);

    GLES20.glDrawArrays(GLES20.GL_LINES, 0, this.numLines*2);

    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mColorHandle);

Blending is enabled with GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA. One more mention is that I am drawing the lines to a texture which is bound to an FBO as a color attachment. I have not added any extra code to enable multisampling for the FBO.

Here is the code I use to setup the FBO and texture:

    int[] fbo = new int[1];
    int[] tex = new int[1];
    enGLES20.glGenTextures(1, tex, 0);
    GLES20.glGenFramebuffers(1, fbo, 0);

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex[0]);
    GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0,GLES20.GL_RGBA, this.width, this.height, 0,GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbo[0]);
    GES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, tex[0], 0);
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);

The resulting lines still look like crap: screenshot

Please help me get these lines to look smooth. BTW there are many different small lines in the screenshot, no curved lines or anything exotic.

0

There are 0 best solutions below