ESTransparency Activity

          
package com.vizit;

import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;
import android.graphics.PointF;
import android.view.ViewGroup;

public class ESTransparency
       extends Activity
{
    private GLSurfaceView view;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Create a GLSurfaceView instance and set it
        // as the ContentView for this Activity.
        view = new MyGLSurfaceView(this);
        setContentView(view,
                       new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                                  ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    @Override
    protected void onResume()
    {
        // The activity must call the GL surface view's onResume() on activity onResume().
        super.onResume();
        view.onResume();
    }

    @Override
    protected void onPause()
    {
        // The activity must call the GL surface view's onPause() on activity onPause().
        super.onPause();
        view.onPause();
    }

    class MyGLSurfaceView extends GLSurfaceView
    {
        private final  TriangleRenderer renderer;
        /** Location of the most recent touch */
        private        PointF           touch    = new PointF();

        public MyGLSurfaceView(Context context)
        {
            super(context);
            // We are using the OpenGL ES 2 API..
            setEGLContextClientVersion(2);
            renderer = new TriangleRenderer();
            // Set the Renderer for drawing on the GLSurfaceView
            setRenderer(renderer);
            // Render the view only when there is a change in the drawing data
            setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        }

        public boolean onTouchEvent (MotionEvent event)
        {

            switch (event.getAction())
            {
                case MotionEvent.ACTION_MOVE:
                    renderer.motion((event.getX() - touch.x)/getWidth()*2,
                                    (touch.y - event.getY())/getHeight()*2);
                    touch.set(event.getX(), event.getY());
                    requestRender();
                    return true;

                case MotionEvent.ACTION_DOWN:
                    touch.set(event.getX(), event.getY());
                    return true;

                default:
                    return super.onTouchEvent(event);
            }
        }
    }
}
          
        

Notes

Initially the small triangle that is behind the first is not visible. This is because the large triangle is in front of the small triangle and it is drawn first. OpenGL does not normally draw an object that is behind an object that has already been drawn.

Reversing the order in which the triangles are drawn makes the smaller triangle visible.

In general, draw opaque objects first, then draw transparent objects back to front.