title: Android: error in putting open gl object on camera view
body: <p>I'm trying to put an object on camera view using open gl, it works good on emulator but when I test it on real android device the camera view or open gl object does not be shown.</p>
  
  <p>this is my MainActivity class</p>
  
  <pre><code>public class MainActivity extends Activity {
  // Our variables 
  CameraPreview cv;
  GLSurfaceView glView;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      final int index = getIntent().getIntExtra("index", 0);
  
      /* Set the screen orientation to landscape, because 
       * the camera preview will be in landscape, and if we 
       * don't do this, then we will get a streached image.*/
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
  
      // requesting to turn the title OFF
      requestWindowFeature(Window.FEATURE_NO_TITLE);
  
      // making it full screen
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
      glView = new GLSurfaceView(this);
      glView.setZOrderOnTop(true);
      glView.getHolder().setFormat( PixelFormat.TRANSLUCENT );
      glView.setRenderer(new GlRenderer(this, index));
      // Now set this as the main view.
      setContentView( glView  );
      Load();
  }
  
  public void Load(){
      // Try to get the camera 
      Camera c = getCameraInstance();        
      // If the camera was received, create the app
      if (c != null){
  
          // Create a new camera view and add it to the layout
          cv = new CameraPreview(this,c);  
          cv.setZOrderOnTop(false);
          if(glView != null){
              // Set the layout as the apps content view 
              addContentView( cv, new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT ) );
          }
  
      }
      // If the camera was not received, close the app
      else {
          Toast toast = Toast.makeText(getApplicationContext(), 
                  "Unable to find camera. Closing.", Toast.LENGTH_SHORT);
          toast.show();
          finish();
      }
  }
  
  /* This method is strait for the Android API */
  /** A safe way to get an instance of the Camera object. */
  public static Camera getCameraInstance(){
      Camera c = null;
  
      try {
          c = Camera.open();// attempt to get a Camera instance
      }
      catch (Exception e){
          // Camera is not available (in use or does not exist)
          e.printStackTrace();
      }
      return c; // returns null if camera is unavailable
  }
  
  
  
  /* Override the onPause method so that we 
   * can release the camera when the app is closing.
   */
  @Override
  protected void onPause() {
      super.onPause();
  
      if (cv != null){
          cv.onPause();
          cv = null;
      }
  }
  
  /* We call Load in our Resume method, because 
   * the app will close if we call it in onCreate
   */
  @Override 
  protected void onResume(){
      super.onResume();
  
  
  }
  }
  </code></pre>
  
  <p>and this is the GlRenderer class</p>
  
  <pre><code>public class GlRenderer implements Renderer {
  
  private Square      square;     // the square
  private Context     context;
  private int imageIndex;
  
  /** Constructor to set the handed over context */
  public GlRenderer(Context context, int index) {
      this.context = context;
      imageIndex = index;
      // initialise the square
      this.square = new Square(imageIndex);
  }
  
  @Override
  public void onDrawFrame(GL10 gl) {
      // clear Screen and Depth Buffer
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  
      // Reset the Modelview Matrix
      gl.glLoadIdentity();
  
      // Drawing
      gl.glTranslatef(0.0f, -1.0f, -4.5f);        // move 5 units INTO the screen
      gl.glRotatef(-90, 1, 0, 0);
                                              // otherwise it will be too large
      square.draw(gl);                        // Draw the triangle
  
  }
  
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
      if(height == 0) {                       //Prevent A Divide By Zero By
          height = 1;                         //Making Height Equal One
      }
  
      gl.glViewport(0, 0, width, height);     //Reset The Current Viewport
      gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Projection Matrix
      gl.glLoadIdentity();                    //Reset The Projection Matrix
  
      //Calculate The Aspect Ratio Of The Window
      GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
  
  
      gl.glMatrixMode(GL10.GL_MODELVIEW);     //Select The Modelview Matrix
      gl.glLoadIdentity();                    //Reset The Modelview Matrix
  }
  
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      // Load the texture for the square
      square.loadGLTexture(gl, this.context);
  
      gl.glEnable(GL10.GL_TEXTURE_2D);            //Enable Texture Mapping ( NEW )
      gl.glShadeModel(GL10.GL_SMOOTH);            //Enable Smooth Shading
      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);    
      gl.glClearDepthf(1.0f);                     //Depth Buffer Setup
      gl.glEnable(GL10.GL_DEPTH_TEST);            //Enables Depth Testing
      gl.glDepthFunc(GL10.GL_LEQUAL);             //The Type Of Depth Testing To Do
  
      //Really Nice Perspective Calculations
      gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I think the main problem is in my open gl code. because when I run the app on real devices the camera view gets displayed for a short time until the open gl object overlays on it. Anyhow I put both classes. In AndroidManifest I chose API 7 as the minimum SDK and both the CAMERA permission and camera hardware feature is added</p>