title: How to fill polygon in android using opengl-es 2.0?
body: <p>I want to draw polygon as shown in images and fill it with colors.
  <a href="https://i.stack.imgur.com/3j5P7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3j5P7.png" alt="Fill Polygon"></a>  <a href="https://i.stack.imgur.com/2IpKq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2IpKq.png" alt="Simple polygon"></a></p>
  
  <p>I have tried polygon using triangle but it will not help me.Anyone know please help me out.</p>
  
  <p>OpenGLProjectRenderer.java</p>
  
  <pre><code>public class OpenGLProjectRenderer implements Renderer {
  
  List&lt;Float&gt; points = new ArrayList&lt;Float&gt;();
  
  private static final String TAG = "Renderer";
  private static final int POSITION_COMPONENT_COUNT = 2;
  private static final int BYTES_PER_FLOAT = 4;
  private FloatBuffer vertexData = ByteBuffer
          .allocateDirect(20000 * BYTES_PER_FLOAT)
          .order(ByteOrder.nativeOrder()).asFloatBuffer();
  private Context context;
  private int program;
  
  private static final String A_POSITION = "a_Position";
  private int aPositionLocation;
  
  private static final String U_COLOR = "u_Color";
  private int uColorLocation;
  
  private HashMap&lt;Integer, ArrayList&lt;Float&gt;&gt; lines = new HashMap&lt;Integer, ArrayList&lt;Float&gt;&gt;();
  int position = 0;
  
  public OpenGLProjectRenderer(Context context) {
  
      this.context = context;
  }
  
  @Override
  public void onDrawFrame(GL10 gl) {
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      glUniform4f(uColorLocation, 1.0f, 0.0f, 0.0f, 1.0f);
  
      for (int p = 0; p &lt; lines.size(); p++) {
  
          vertexData.put(toFloatarray(lines.get(p)));
          int vertices = (int) lines.get(p).size() / 2;
          int b = vertices % 4 == 0 ? vertices-1 : vertices - 2;
          Log.d(TAG,""+lines.size());
          glDrawArrays(GLES20.GL_LINE_LOOP, 0, lines.size());
          vertexData.clear();
      }
  
  }
  
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
      gl.glViewport(0, 0, width, height);
  
  }
  
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  
      String vertexShaderSource = TextResourceReader.readTextFileFromResource(
              context, R.raw.simple_vertex_shader);
      String fragmentShaderSource = TextResourceReader.readTextFileFromResource(
              context, R.raw.simple_fragment_shader);
  
      int vertexShader = ShaderHelper.compileVertexShader(vertexShaderSource);
      int fragmentShader = ShaderHelper
              .compileFragmentShader(fragmentShaderSource);
      program = ShaderHelper.linkProgram(vertexShader, fragmentShader);
      ShaderHelper.validateProgram(program);
      glUseProgram(program);
      uColorLocation = glGetUniformLocation(program, U_COLOR);
      aPositionLocation = glGetAttribLocation(program, A_POSITION);
      vertexData.position(0);
      glVertexAttribPointer(aPositionLocation, POSITION_COMPONENT_COUNT,
              GL_FLOAT, false, 0, vertexData);
      glEnableVertexAttribArray(aPositionLocation);
  }
  
  ArrayList&lt;Float&gt; temp = new ArrayList&lt;Float&gt;();
  
  public void handleTouchPress(float normalizedX, float normalizedY) {
      Log.v(TAG + " handleTouchPress", points.size() + "");       
  
      temp.add(normalizedX);
      temp.add(normalizedY);
  
      lines.put(position, temp);
  }
  
  public void handleTouchDrag(float normalizedX, float normalizedY) {
  
      Log.v(TAG + " handleTouchDrag", points.size() + "");
  }
  
  public float[] toFloatarray(List&lt;Float&gt; floatList) {
  
      float[] floatArray = new float[floatList.size()];
      int i = 0;
  
      for (Float f : floatList) {
          floatArray[i++] = (f != null ? f : Float.NaN);
      }
  
      return floatArray;
  }
  
  public void handleTouchUp(float normalizedX, float normalizedY) {
      Log.v(TAG + " handleTouchUp", points.size() + "");
  
      position++;
  
  }}
  </code></pre>
  
  <p>Using above code I am able to draw polygon using above code using GL_LINE_LOOP but not able to fill created polygon.</p>