title: Android and OpenGL - See object through another object
body: <p>I'm a total noob and I'm trying to display a little submarine I built in a 3d modeling program in opengl (Blender). </p>
  
  <p>The submarine is built using a long cylinder with a sphere intersecting on the end of it. </p>
  
  <p>The problem that I'm getting is that when I look at the result, I can see the entire sphere through the cylinder. I can also see the end of the cylinder through the sphere. This appears when I have lighting on. I'm using ambient and diffuse lighting. I just want to see half the sphere on the outside of the cylinder and I don't want to see any innards.</p>
  
  <p>I have face culling on and it removes the front faces of both objects, but I clearly see the sphere. </p>
  
  <p>Below I pasted my onSurfaceCreated function where I set up all the opengl parameters. Any suggestions are appreciated!</p>
  
  <pre><code>@Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      //
      gl.glEnable(GL10.GL_DEPTH_TEST);
      //gl.glMatrixMode(GL10.GL_PROJECTION);
  
      gl.glMatrixMode(GL10.GL_MODELVIEW);
  
      gl.glEnable(GL10.GL_POLYGON_OFFSET_FILL);
  
      gl.glEnable(GL10.GL_LIGHTING);
      gl.glEnable(GL10.GL_LIGHT0);
  
      // Define the ambient component of the first light
      float[] light0Ambient = {0.1f, 0.1f, 0.1f, 1.0f};        
      gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, FloatBufferFromFloatArray(light0Ambient, 4));
  
      // Define the diffuse component of the first light
      float[] light0Diffuse = {0.7f, 0.7f, 0.7f, 1.0f};
      gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, FloatBufferFromFloatArray(light0Diffuse, 4));
  
      // Define the specular component and shininess of the first light
      float[] light0Specular = {0.7f, 0.7f, 0.7f, 1.0f};
      float light0Shininess = 0.4f;
      //gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, FloatBufferFromFloatArray(light0Specular, 4));        
  
      // Define the position of the first light
      float[] light0Position = {1.0f, 0.0f, 0.0f, 0.0f};
      gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, FloatBufferFromFloatArray(light0Position, 4)); 
  
      // Define a direction vector for the light, this one points correct down the Z axis
      float[] light0Direction = {0.0f, 0.0f, -1.0f};
      //gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPOT_DIRECTION, FloatBufferFromFloatArray(light0Direction, 3));
  
      // Define a cutoff angle. This defines a 90° field of vision, since the cutoff
      // is number of degrees to each side of an imaginary line drawn from the light's
      // position along the vector supplied in GL_SPOT_DIRECTION above
      //gl.glLightf(gl.GL_LIGHT0, gl.GL_SPOT_CUTOFF, 180.0f);
  
      gl.glEnable(GL10.GL_CULL_FACE);
      // which is the front? the one which is drawn counter clockwise
      gl.glFrontFace(GL10.GL_CCW);
      // which one should NOT be drawn
      gl.glCullFace(GL10.GL_BACK);
  
      gl.glClearDepthf(10f);
      gl.glPolygonOffset(1.0f, 2);
  
      initShape();
  
      gl.glScalef(0.5f, 0.5f, 0.5f);
  }
  </code></pre>