代码之家  ›  专栏  ›  技术社区  ›  Yaroslav Mytkalyk

已忽略OpenGL ES 2.0颜色数组半透明

  •  0
  • Yaroslav Mytkalyk  · 技术社区  · 8 年前
    “统一Mat4 umvMatrix;”“+ “可变vec4 vcolor;”“+ “gl_position=umvpMatrix*vposition;”。+ 私有静态最终字符串片段着色程序代码=
    
    linecoordinatesbuffer.位置(0);
    
    gles20.glclear(gles20.gl_color_buffer_bit_gles20.gl_depth_buffer_bit);
    
    final int positionhandle=gles20.glgetattriblocation(program,“vposition”);
    
    gles20.glvertexattribpointer(gles20.glvertexattribpointer)(
    0,
    
    final int colorhandle=gles20.glgetattriblocation(程序,“acolor”);
    
    
    final int mvpmatrixhandle=gles20.glgetUniformLocation(程序,“umvpMatrix”);
    
    gles20.gldrawarray(gles20.gl_三角形,0,24);
    
    
    533,790,524,787,483,902,
    76,1513,177,1636,83,1507,
    950、413、905、591、960、415、
    
    
    
    -1,-1,-1,-122,
    -1,-1,-1,-122,
    -1,-1,-1,97,
    -1,-1,-1,-110,
    -1,-1,-1,-110,
    -1,-1,-1,72,
    -1,-1,-1,72,
    
    
    
    

    预期输出:相同,但在线条上应用了alpha

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    

        @Override
        public void onDrawFrame(GL10 gl) {
            lineCoordinatesBuffer.position(0);
            lineColorBuffer.position(0);
    
            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
            GLES20.glUseProgram(program);
    
            final int positionHandle = GLES20.glGetAttribLocation(program, "vPosition");
            GLES20.glEnableVertexAttribArray(positionHandle);
    
            GLES20.glVertexAttribPointer(
                    positionHandle,
                    COORDINATES_PER_VERTEX,
                    GLES20.GL_SHORT,
                    false,
                    0,
                    lineCoordinatesBuffer);
    
            final int colorHandle = GLES20.glGetAttribLocation(program, "aColor");
            GLES20.glEnableVertexAttribArray(colorHandle);
    
            GLES20.glVertexAttribPointer(
                    colorHandle,
                    COLOR_BYTES_PER_VERTEX,
                    GLES20.GL_UNSIGNED_BYTE,
                    false,
                    0,
                    lineColorBuffer);
    
            final int mvpMatrixHandle = GLES20.glGetUniformLocation(program, "uMVPMatrix");
            GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0);
    
            GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 24);
        }
    

    493, 906, 533, 790, 483, 902,
    533, 790, 524, 787, 483, 902,
    76, 1513, 177, 1636, 83, 1507,
    177, 1636, 184, 1630, 83, 1507,
    988, 439, 928, 531, 996, 444,
    928, 531, 936, 536, 996, 444,
    950, 413, 905, 591, 960, 415,
    905, 591, 915, 594, 960, 415
    

    线路颜色缓冲器

    -1, -1, -1, -122,
    -1, -1, -1, -122,
    -1, -1, -1, -122,
    -1, -1, -1, -122,
    -1, -1, -1, -122,
    -1, -1, -1, -122,
    -1, -1, -1, 97,
    -1, -1, -1, 97,
    -1, -1, -1, 97,
    -1, -1, -1, 97,
    -1, -1, -1, 97,
    -1, -1, -1, 97,
    -1, -1, -1, -110,
    -1, -1, -1, -110,
    -1, -1, -1, -110,
    -1, -1, -1, -110,
    -1, -1, -1, -110,
    -1, -1, -1, -110,
    -1, -1, -1, 72,
    -1, -1, -1, 72,
    -1, -1, -1, 72,
    -1, -1, -1, 72,
    -1, -1, -1, 72,
    -1, -1, -1, 72
    

    enter image description here

    1 回复  |  直到 8 年前
        1
  •  1
  •   solidpixel    8 年前

    尝试设置 normalized glVertexAttribPointer() true

    推荐文章