title: Android draw texture extension drawing white textures
body: <p>I started writing a game for Android using OpenGL-ES and just finished the draw code which uses the glDrawTexfOES extension. When I tested it on the emulator it works fine but testing it on my Samsung Galaxy S2 it seems all the textures are drawn white.</p>
  
  <p>To make sure I didn't make any mistakes I copied the source from a tutorial and ran it with the same results. The tutorial code I am using can be seen <a href="http://apecoder.net/2010/11/17/using-2d-opengl-on-android-part-2/" rel="nofollow">here</a>.</p>
  
  <p>My textures are .PNG format and power of two and I am loading from the R.drawable folder although I have tried some other locations such as drawable-nodpi as I have seen suggested.</p>
  
  <p>I have also checked the result of glGenTextures which I have read can give odd values for certain phones but seems to be giving the correct values (1,2,3..).</p>
  
  <p>Does anybody know why this could be happening or suggest some other checks I can do to figure out what is going wrong?</p>
  
  <p>Here is a slightly modified version of the example code I linked above to keep things simple.</p>
  
  <pre><code>public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
  
      gl10.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
      // Set the background colour to black ( rgba ).
      gl10.glClearColor(0.0f, 0.0f, 0.0f, 1);
      // Enable Flat Shading.
      gl10.glShadeModel(GL10.GL_FLAT);
      // We don't need to worry about depth testing!
      gl10.glDisable(GL10.GL_DEPTH_TEST);
      // Set OpenGL to optimise for 2D Textures
      gl10.glEnable(GL10.GL_TEXTURE_2D);
      // Disable 3D specific features.
      gl10.glDisable(GL10.GL_DITHER);
      gl10.glDisable(GL10.GL_LIGHTING);
  
      gl10.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
      // Initial clear of the screen.
      gl10.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  
      // Test for draw texture
  
      // Test for device specific extensions
      String extensions = gl10.glGetString(GL10.GL_EXTENSIONS);
      boolean drawTexture = extensions.contains("draw_texture");
      Log.i("OpenGL Support - ver.:",
              gl10.glGetString(GL10.GL_VERSION) + " renderer:" +
              gl10.glGetString(GL10.GL_RENDERER) + " : " +
              (drawTexture ? "good to go!" : "forget it!!"));
  
      // LOAD TEXTURE
  
      mTextureName = new int[1];
  
      // Generate Texture ID
      gl10.glGenTextures(1, mTextureName, 0);
      assert gl10.glGetError() == GL10.GL_NO_ERROR;
  
      // Bind texture id / target (we want 2D of course)
      gl10.glBindTexture(GL10.GL_TEXTURE_2D,  mTextureName[0]);
  
       // Open and input stream and read the image
      InputStream is = mContext.getResources().openRawResource(R.drawable.asteroid);
      Bitmap bitmap;
      try {
          bitmap = BitmapFactory.decodeStream(is);
      } finally {
          try {
              is.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      // Build our crop region to be the size of the bitmap (ie full image)
      mCrop = new int[4];
      mCrop[0] = 0;
      mCrop[1] = imageHeight = bitmap.getHeight();
      mCrop[2] = imageWidth = bitmap.getWidth();
      mCrop[3] = -bitmap.getHeight();
  
  
      GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
      assert gl10.glGetError() == GL10.GL_NO_ERROR;
  
      bitmap.recycle();
  }
  
  public void onSurfaceChanged(GL10 gl10, int i, int i1) {
  
      gl10.glViewport(0, 0, i, i1);
      /*
       * Set our projection matrix. This doesn't have to be done each time we
       * draw, but usually a new projection needs to be set when the viewport
       * is resized.
       */
      float ratio = (float) i / i1;
      gl10.glMatrixMode(GL10.GL_PROJECTION);
      gl10.glLoadIdentity();
      gl10.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
  }
  
  
  public void onDrawFrame(GL10 gl) {
      // Just clear the screen and depth buffer.
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  
      // Begin drawing
      //--------------
      // These function calls can be experimented with for various effects such as transparency
      // although certain functionality maybe device specific.
      gl.glShadeModel(GL10.GL_FLAT);
      gl.glEnable(GL10.GL_BLEND);
      gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
      gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
  
      // Setup correct projection matrix
      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glPushMatrix();
      gl.glLoadIdentity();
      gl.glOrthof(0.0f, mWidth, 0.0f, mHeight, 0.0f, 1.0f);
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glPushMatrix();
      gl.glLoadIdentity();
  
      gl.glEnable(GL10.GL_TEXTURE_2D);
  
      // Draw all Textures
      gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureName[0]);
      ((GL11)gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCrop, 0);
      ((GL11Ext)gl).glDrawTexfOES(0, 0, 0, imageWidth, imageHeight);
  
      // Finish drawing
      gl.glDisable(GL10.GL_BLEND);
      gl.glMatrixMode(GL10.GL_PROJECTION);
      gl.glPopMatrix();
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glPopMatrix();
  }
  </code></pre>