2011-01-15 10 views

Antwort

3

ist es nicht so schwierig. Dies sind die Hauptteile:

public static Bitmap loadBitmapFromId(Context context, int bitmapId) { 
     InputStream is = context.getResources().openRawResource(bitmapId); 
     try { 
      BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); 
      bitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565; 
      return BitmapFactory.decodeStream(is, null, bitmapOptions); 
     } catch (Exception ex) { 
      Log.e("bitmap loading exeption", ex.getLocalizedMessage()); 
      return null; 
     } 
    } 

Die Bitmap.Config.RGB_565 ist hier wichtig. Dann fügen Sie die Bitmap hinzu und erhalten Sie Ihre Textur-ID wie gewohnt.

Jetzt im onSurfaceCreated (GL10 gl, EGLConfig config) Ihres Renderer hinzufügen:

// Transparancy 
    // important: transparent objects have to be drawn last! 
    gl.glEnable(GL10.GL_BLEND); 
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 

Und die Zeichnung Teil (Sie tun dies wahrscheinlich schon):

 // first disable color_array for save: 
     gl.glDisableClientState(GL10.GL_COLOR_ARRAY); 

     // 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); 

     gl.glEnable(GL10.GL_TEXTURE_2D); 

     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, 
       GL10.GL_LINEAR); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, 
       GL10.GL_LINEAR); 

     gl.glBindTexture(GL10.GL_TEXTURE_2D, myTextureId); 
     gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); 
     gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); 

     gl.glDrawArrays(drawMode, 0, verticesCount); 

     gl.glDisable(GL10.GL_TEXTURE_2D); 
     // Disable the vertices buffer. 
     gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 
+0

sehr gut, Danke! – lacas