android openGL ES 01

实现功能:点击屏幕背景颜色变化。

 

三个类:

VortexRenderer,VortexView,Vortex

 

 

VortexRenderer

package org.jun.opengl01;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;

public class VortexRenderer implements GLSurfaceView.Renderer {
	private static final String LOG_TAG = VortexRenderer.class.getSimpleName();

	private float _red = 0.9f;
	private float _green = 0.2f;
	private float _blue = 0.2f;
	
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		// Do nothing special.
	}

	public void onSurfaceChanged(GL10 gl, int w, int h) {
		gl.glViewport(0, 0, w, h);
	}

	public void onDrawFrame(GL10 gl) {
		// define the color we want to be displayed as the "clipping wall"
		gl.glClearColor(_red, _green, _blue, 1.0f);
		// clear the color buffer to show the ClearColor we called above...
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
	}
	
	public void setColor(float r, float g, float b) {
		_red = r;
		_green = g;
		_blue = b;
	}
}

 

 

VortexView:

package org.jun.opengl01;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;

public class VortexView extends GLSurfaceView {
	private static final String LOG_TAG = VortexView.class.getSimpleName();
	private VortexRenderer _renderer;

	public VortexView(Context context) {
		super(context);
		_renderer = new VortexRenderer();
		setRenderer(_renderer);
	}

	public boolean onTouchEvent(final MotionEvent event) {
		queueEvent(new Runnable() {
			public void run() {
				_renderer.setColor(event.getX() / getWidth(), event.getY()
						/ getHeight(), 1.0f);
			}
		});
		return true;
	}
}


 

 

Vortex

package org.jun.opengl01;

import android.app.Activity;
import android.os.Bundle;

public class Vortex extends Activity {
    /** Called when the activity is first created. */
    private static final String LOG_TAG = Vortex.class.getSimpleName();
    private VortexView _vortexView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _vortexView = new VortexView(this);
    setContentView(_vortexView);
    }
}


 

效果:

android openGL ES 01_第1张图片

你可能感兴趣的:(android,String,Class,buffer,import,float)