opengl显示

来源:互联网 发布:mac mini好吗 编辑:程序博客网 时间:2024/04/27 01:59


package com.android.opengl;










import com.hsae.monitor.GLRenderer;


import android.app.ActivityManager;




import android.content.Context;


import android.content.pm.ConfigurationInfo;










import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;




public class ExecuteActivity extends MainActivity {
private static final String TAG = "ExecuteActivity";
public static float scan = 1.0f;
public static float tran = 0.0f;
private GLSurfaceView mGLSurfaceView;
private GLRenderer mRender;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("IVI", "Goto_RecordCamera");
Goto_RecordCamera("/dev/video0");
Goto_layout_Main();
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "On Destroy!");
}


public void Goto_RecordCamera(String CameraDev) {
OpenCamera(CameraDev);
}


public void Goto_layout_Main() {
// setContentView(R.layout.activity_main);
/*LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = (View) inflater.inflate(R.layout.activity_main, null, true);
setContentView(view);*/
/*********************************分割线************************/
   mGLSurfaceView = new GLSurfaceView(this); 
   setContentView(mGLSurfaceView);
// Check if the system supports OpenGL ES 2.0.
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo = activityManager
.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;


if (supportsEs2) {
// Request an OpenGL ES 2.0 compatible context.
mGLSurfaceView.setEGLContextClientVersion(2);


mRender = new GLRenderer(this);
// Set the renderer to our demo renderer, defined below.
mGLSurfaceView.setRenderer(mRender);
mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
} else {
// This is where you could create an OpenGL ES 1.x compatible
// renderer if you wanted to support both ES 1 and ES 2.
return;
}
//LinearLayout lay=(LinearLayout)findViewById(R.id.MonitorView);
//lay.addView(mGLSurfaceView);
}

  /*********************************分割线************************/




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


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

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_MOVE) {
// System.out.println(event.getX() + "," + event.getY());
this.scan = ev.getY() / 120;
this.tran = (ev.getX() - 400) / 200;
}
System.out.println("dispatchTouchEvent"+this.scan);
System.out.println("dispatchTouchEvent"+this.tran);
return super.dispatchTouchEvent(ev);
}


@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
// System.out.println(event.getX() + "," + event.getY());
this.scan = event.getY() / 120;
this.tran = (event.getX() - 400) / 200;
}
System.out.println(this.scan);
System.out.println(this.tran);
return super.onTouchEvent(event);
}


public float getScan() {
return this.scan;
}


}
0 0
原创粉丝点击