title: Android OpenGL ES rendering subdivided Mesh
body: <p>I'm trying to render a subdivided mesh with a displacement texture on it and a color texture. To do so I go through every pixel, create a vertex for it, and move that vertex according to a black and white image I have. The problem is that when I render it, I get something that looks a bit like TV snow. <img src="https://i.stack.imgur.com/35Sbm.png" alt="enter image description here"></p>
  
  <p>Here's the relevant code:</p>
  
  <pre><code>public Plane(Bitmap image, Bitmap depth)
  {
      this.image = image; //color image
      this.depth = depth; //BW depth image
      this.w = image.getWidth();
      this.h = image.getHeight();
  
      vertexCoords = vertexArray(); //places vertices in 3d
      drawOrder = orderArray(); //sets the draw order
      colorCoords = colorArray(); //sets color per vertex
  
      ByteBuffer bb = ByteBuffer.allocateDirect(vertexCoords.length * 4);
      bb.order(ByteOrder.nativeOrder());
      vertexBuffer = bb.asFloatBuffer();
      vertexBuffer.put(vertexCoords);
      vertexBuffer.position(0);
  
      ByteBuffer dlb = ByteBuffer.allocateDirect(drawOrder.length * 4);
      dlb.order(ByteOrder.nativeOrder());
      drawListBuffer = dlb.asShortBuffer();
      drawListBuffer.put(drawOrder);
      drawListBuffer.position(0);
  
      ByteBuffer cbb = ByteBuffer.allocateDirect(colorCoords.length * 4);
      cbb.order(ByteOrder.nativeOrder());
      colorBuffer = cbb.asFloatBuffer();
      colorBuffer.put(colorCoords);
      colorBuffer.position(0);
  }
  
  public void draw(GL10 gl) {
      // Counter-clockwise winding.
      gl.glFrontFace(GL10.GL_CCW);
      // Enable face culling.
      gl.glEnable(GL10.GL_CULL_FACE);
      // What faces to remove with the face culling.
      gl.glCullFace(GL10.GL_BACK);
  
      // Enabled the vertices buffer for writing and to be used during
      // rendering.
      gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
      // Specifies the location and data format of an array of vertex
      // coordinates to use when rendering.
      gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
  
      // Enable the color array buffer to be used during rendering.
      gl.glEnableClientState(GL10.GL_COLOR_ARRAY); // NEW LINE ADDED.
      // Point out the where the color buffer is.
      gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer); // NEW LINE ADDED.
  
      gl.glDrawElements(GL10.GL_TRIANGLES, drawOrder.length,
              GL10.GL_UNSIGNED_SHORT, drawListBuffer);
  
      // Disable the vertices buffer.
      gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
      // Disable face culling.
      gl.glDisable(GL10.GL_CULL_FACE);
  
      gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
  }
  </code></pre>
  
  <p>What can I do to actually view the model, instead of this snow thing? The patterns change if I turn my screen on and off, and they sometimes change randomly. It seems that the colors present in the original bitmap are also present in the snow (the snow color changes with different pictures), so I know I'm doing something right, I just don't know what's wrong here.</p>
  
  <p>EDIT: here's the code for <code>vertexArray()</code></p>
  
  <pre><code>public float[] vertexArray()
  {
      int totalPoints = w*h;
      float[] arr = new float[totalPoints*3];
  
      int i = 0;
      for(int y = 0; y&lt;h; y++)
      {
          for(int x = 0; x&lt;w; x++)
          {
              arr[i] = x * 0.01f;
              arr[i+1] = y * 0.01f;
              arr[i+2] = 1.0f;//getDepth(x,y);
              i+=3;
          }
      }
  
      return arr;
  }
  </code></pre>