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 ESPrograms
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);
}
}
}
}
Uses multiple programs to render the vertices in different styles. This is the preferred method to provide richer functionality. Do not use complex shaders with conditions, build multiple small programs and use the different programs for different tasks.