Example usage for android.opengl GLSurfaceView RENDERMODE_WHEN_DIRTY

List of usage examples for android.opengl GLSurfaceView RENDERMODE_WHEN_DIRTY

Introduction

In this page you can find the example usage for android.opengl GLSurfaceView RENDERMODE_WHEN_DIRTY.

Prototype

int RENDERMODE_WHEN_DIRTY

To view the source code for android.opengl GLSurfaceView RENDERMODE_WHEN_DIRTY.

Click Source Link

Document

The renderer only renders when the surface is created, or when #requestRender is called.

Usage

From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java

public MyGLSurfaceView(Context context) {
    super(context);

    // Create an OpenGL ES 3.0 context.
    setEGLContextClientVersion(3);/*from   w w  w .  j  a  v a2 s.co m*/

    // Sets a paper background to the scene
    setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setBackgroundResource(R.drawable.paperbright);
    setZOrderOnTop(true);

    // Set the Renderer for drawing on the GLSurfaceView
    mRenderer = new MyGLRenderer(context);
    setRenderer(mRenderer);

    // Render the view only when there is a change in the drawing data
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    setPreserveEGLContextOnPause(true);
}

From source file:com.example.android.mediaeffects.MediaEffectsFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mEffectView = (GLSurfaceView) view.findViewById(R.id.effectsview);
    mEffectView.setEGLContextClientVersion(2);
    mEffectView.setRenderer(this);
    mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    if (null != savedInstanceState && savedInstanceState.containsKey(STATE_CURRENT_EFFECT)) {
        setCurrentEffect(savedInstanceState.getInt(STATE_CURRENT_EFFECT));
    } else {/*www.  j  a va  2  s.  co m*/
        setCurrentEffect(R.id.none);
    }
}

From source file:com.example.ex_templete.TouchRotateFragment.java

public TouchSurfaceView(Context context) {
    super(context);
    mRenderer = new CubeRenderer();
    setRenderer(mRenderer);
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}

From source file:com.example.vendrisample.HelloEffects.java

License:asdf

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*  www.ja va2  s  .  c om*/

    /**
     * Initialize the renderer and tell it to only render when explicity
     * requested with the RENDERMODE_WHEN_DIRTY option
     */
    mEffectView = (GLSurfaceView) findViewById(R.id.effectsview);
    mEffectView.setEGLContextClientVersion(2);
    mEffectView.setRenderer(this);
    mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    // initialized the listener as a varaiable for further use.
    if (vendriListener == null) {
        vendriListener = this;
    }

    /*Below two lines are to test the scoped variables feature where added
    vendriVar through managementsite*/
    if (savedInstanceState == null) {
        String[] toppings = { "Cheese", "Pepperoni", "Black Olives" };
        vendriVar = toppings;
        Vendri.init(this, vendriListener, vendriPID);
    }
}

From source file:com.wlanjie.streaming.camera.CameraView.java

@SuppressWarnings("WrongConstant")
public CameraView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // Internal setup

    final View view = View.inflate(context, R.layout.texture_view, this);
    mGLSurfaceView = (GLSurfaceView) view.findViewById(R.id.gl_surface_view);
    mGLSurfaceView.setEGLContextClientVersion(2);
    mGLSurfaceView.setRenderer(this);
    mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    mTextureId = OpenGLUtils.getExternalOESTextureID();
    mSurfaceTexture = new SurfaceTexture(mTextureId);

    mCallbacks = new CallbackBridge();
    if (Build.VERSION.SDK_INT < 21) {
        mImpl = new Camera1(mCallbacks);
    } else if (Build.VERSION.SDK_INT < 23) {
        mImpl = new Camera2(mCallbacks, context);
    } else {/*ww  w . ja v  a2s .  c  o m*/
        mImpl = new Camera2Api23(mCallbacks, context);
    }
    mImpl.setPreviewSurface(mSurfaceTexture);
    // Attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CameraView, defStyleAttr,
            R.style.Widget_CameraView);
    mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, false);
    setFacing(a.getInt(R.styleable.CameraView_facing, FACING_BACK));
    String aspectRatio = a.getString(R.styleable.CameraView_aspectRatio);
    if (aspectRatio != null) {
        setAspectRatio(AspectRatio.parse(aspectRatio));
    } else {
        setAspectRatio(Constants.DEFAULT_ASPECT_RATIO);
    }
    setFlash(a.getInt(R.styleable.CameraView_flash, Constants.FLASH_AUTO));
    a.recycle();
    // Display orientation detector
    mDisplayOrientationDetector = new DisplayOrientationDetector(context) {
        @Override
        public void onDisplayOrientationChanged(int displayOrientation) {
            mImpl.setDisplayOrientation(displayOrientation);
        }
    };
}

From source file:org.mklab.mikity.android.CanvasFragment.java

/**
 * {@inheritDoc}/*from w  ww .  j  a va 2 s  . c o m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    this.view = inflater.inflate(R.layout.fragment_canvas, container, false);
    this.view.setOnTouchListener(this);

    this.glView = (GLSurfaceView) this.view.findViewById(R.id.glview1);
    this.glView.setEGLConfigChooser(8, 8, 8, 8, 16, 8);

    getResources();

    final ConfigurationModel configuration = new ConfigurationModel();
    configuration.setEye(new EyeModel(5.0f, 0.0f, 0.0f));
    configuration.setLookAtPoiint(new LookAtPointModel(0.0f, 0.0f, 0.0f));
    configuration.setLight(new LightModel(10.0f, 10.0f, 20.0f));

    this.objectRenderer = new OpenglesObjectRenderer(this.glView, configuration);
    this.modeler = new OpenglesModeler(this.objectRenderer);

    this.glView.setRenderer(this.objectRenderer);
    this.glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    this.isInitialScreenSize = false;

    createNewModelData();

    this.gestureDetector = new ScaleGestureDetector(this.getActivity(), this);

    return this.view;
}

From source file:com.projecttango.experiments.javapointcloud.PointCloudActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jpoint_cloud);
    setTitle(R.string.app_name);//from w  w  w . java2s.  c  o  m
    outFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "shoopdawoop.txt");
    if (!outFile.exists())
        try {
            outFile.createNewFile();
        } catch (IOException e1) {
            throw new AssertionError();
            // TODO Auto-generated catch block
        }
    mPoseTextView = (TextView) findViewById(R.id.pose);
    mQuatTextView = (TextView) findViewById(R.id.quat);
    mPoseCountTextView = (TextView) findViewById(R.id.posecount);
    mDeltaTextView = (TextView) findViewById(R.id.deltatime);
    mTangoEventTextView = (TextView) findViewById(R.id.tangoevent);
    mPoseStatusTextView = (TextView) findViewById(R.id.status);
    mPointCountTextView = (TextView) findViewById(R.id.pointCount);
    mTangoServiceVersionTextView = (TextView) findViewById(R.id.version);
    mApplicationVersionTextView = (TextView) findViewById(R.id.appversion);
    mAverageZTextView = (TextView) findViewById(R.id.averageZ);
    mFrequencyTextView = (TextView) findViewById(R.id.frameDelta);

    mFirstPersonButton = (Button) findViewById(R.id.first_person_button);
    mFirstPersonButton.setOnClickListener(this);
    mThirdPersonButton = (Button) findViewById(R.id.third_person_button);
    mThirdPersonButton.setOnClickListener(this);
    mTopDownButton = (Button) findViewById(R.id.top_down_button);
    mTopDownButton.setOnClickListener(this);

    mTango = new Tango(this);
    Log.d(TAG, "Tango constructed on activity context");

    mConfig = new TangoConfig();
    mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
    mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);

    int maxDepthPoints = mConfig.getInt("max_point_cloud_elements");
    mRenderer = new PCRenderer(maxDepthPoints);
    mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
    mGLView.setEGLContextClientVersion(2);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    PackageInfo packageInfo;
    try {
        packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
        mApplicationVersionTextView.setText(packageInfo.versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Display the version of Tango Service
    mServiceVersion = mConfig.getString("tango_service_library_version");
    mTangoServiceVersionTextView.setText(mServiceVersion);
    mIsTangoServiceConnected = false;

}

From source file:com.kitware.tangoproject.paraviewtangorecorder.PointCloudActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jpoint_cloud);
    setTitle(R.string.app_name);//from   ww w  .j  av  a2  s .  c om

    mPoseTextView = (TextView) findViewById(R.id.pose);
    mQuatTextView = (TextView) findViewById(R.id.quat);
    mPoseCountTextView = (TextView) findViewById(R.id.posecount);
    mDeltaTextView = (TextView) findViewById(R.id.deltatime);
    mTangoEventTextView = (TextView) findViewById(R.id.tangoevent);
    mPoseStatusTextView = (TextView) findViewById(R.id.status);
    mPointCountTextView = (TextView) findViewById(R.id.pointCount);
    mTangoServiceVersionTextView = (TextView) findViewById(R.id.version);
    mApplicationVersionTextView = (TextView) findViewById(R.id.appversion);
    mAverageZTextView = (TextView) findViewById(R.id.averageZ);
    mFrequencyTextView = (TextView) findViewById(R.id.frameDelta);

    mFirstPersonButton = (Button) findViewById(R.id.first_person_button);
    mFirstPersonButton.setOnClickListener(this);
    mThirdPersonButton = (Button) findViewById(R.id.third_person_button);
    mThirdPersonButton.setOnClickListener(this);
    mTopDownButton = (Button) findViewById(R.id.top_down_button);
    mTopDownButton.setOnClickListener(this);

    mTango = new Tango(this);
    mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
    mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);

    int maxDepthPoints = mConfig.getInt("max_point_cloud_elements");
    mRenderer = new PCRenderer(maxDepthPoints);
    mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
    mGLView.setEGLContextClientVersion(2);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    PackageInfo packageInfo;
    try {
        packageInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
        mApplicationVersionTextView.setText(packageInfo.versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    // Display the version of Tango Service
    mServiceVersion = mConfig.getString("tango_service_library_version");
    mTangoServiceVersionTextView.setText(mServiceVersion);
    mIsTangoServiceConnected = false;

    // My initializations
    mTakeSnapButton = (Button) findViewById(R.id.take_snap_button);
    mTakeSnapButton.setOnClickListener(this);
    mFilesWrittenToSDCardTextView = (TextView) findViewById(R.id.fileWritten);
    mAutoModeSwitch = (Switch) findViewById(R.id.auto_mode_switch);
    mAutoModeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            autoMode_SwitchChanged(isChecked);
        }
    });
    mRecordSwitch = (Switch) findViewById(R.id.record_switch);
    mRecordSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            record_SwitchChanged(isChecked);
        }
    });
    mWaitingProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mWaitingProgressBar.setVisibility(View.VISIBLE);
    mWaitingTextView = (TextView) findViewById(R.id.waitingTextView);
    mWaitingTextView.setVisibility(View.VISIBLE);
    mWaitingTextView.setText(R.string.waitInitialize);
    mWaitingLinearLayout = (LinearLayout) findViewById(R.id.waitingBarLayout);
    mWaitingLinearLayout.setVisibility(View.VISIBLE);

    mFilename = "";
    mNumberOfFilesWritten = 0;
    mTimeToTakeSnap = false;
    mTakeSnapButton.setEnabled(false);
    mAutoMode = false;
    mAutoModeSwitch.setChecked(false);
    mIsRecording = false;
    mRecordSwitch.setChecked(false);
    mPosePositionBuffer = new ArrayList<float[]>();
    mPoseOrientationBuffer = new ArrayList<float[]>();
    mPoseTimestampBuffer = new ArrayList<Float>();
    mFilenameBuffer = new ArrayList<String>();
    mNumPoseInSequence = 0;
    mXyzIjCallbackCount = 0;
    mutex_on_mIsRecording = new Semaphore(1, true);
    mAppIsStarting = true;
    // End of My initializations
}

From source file:gl.iglou.scenegraph.MatModeInterface.java

public void ScreenShot(View v) {
    Log.v(TAG, "Souriez!!!");
    //mView.Shoot();
    //GL2JNILib.TakeSnapshot();
    //while(!GL2JNILib.IsSnapshotReady()) { Log.v(TAG,"Waiting for snapshot!!"); }

    GLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    GL2JNILib.SnapshotMode(true);/*from  w  w w . j  av  a  2  s .  co  m*/
    GL2JNILib.TakeSnapshot();
    GLView.requestRender();

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        public void run() {
            GLView.getBitmapJNI();
            photo.setImageBitmap(GLView.mBitmap);
            snapshotContainer.setVisibility(View.VISIBLE);

        }
    }, 100);
}

From source file:jp.co.cyberagent.android.gpuimage.sample.activity.ActivityCamera.java

License:asdf

private void takePicture() {
    // TODO get a size that is about the size of the screen
    Camera.Parameters params = mCameraLoader.mCameraInstance.getParameters();
    params.setPictureSize(1280, 960);// w w  w.  j  a v  a2  s  .  co  m
    params.setRotation(90);
    mCameraLoader.mCameraInstance.setParameters(params);
    for (Camera.Size size2 : mCameraLoader.mCameraInstance.getParameters().getSupportedPictureSizes()) {
        Log.i("ASDF", "Supported: " + size2.width + "x" + size2.height);
    }
    mCameraLoader.mCameraInstance.takePicture(null, null, new Camera.PictureCallback() {

        @Override
        public void onPictureTaken(byte[] data, final Camera camera) {

            final File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
            if (pictureFile == null) {
                Log.d("ASDF", "Error creating media file, check storage permissions");
                return;
            }

            try {
                FileOutputStream fos = new FileOutputStream(pictureFile);
                fos.write(data);
                fos.close();
            } catch (FileNotFoundException e) {
                Log.d("ASDF", "File not found: " + e.getMessage());
            } catch (IOException e) {
                Log.d("ASDF", "Error accessing file: " + e.getMessage());
            }

            data = null;
            Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
            // mGPUImage.setImage(bitmap);
            final GLSurfaceView view = (GLSurfaceView) findViewById(R.id.surfaceView);
            view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
            mGPUImage.saveToPictures(bitmap, "GPUImage", System.currentTimeMillis() + ".jpg",
                    new OnPictureSavedListener() {

                        @Override
                        public void onPictureSaved(final Uri uri) {
                            pictureFile.delete();
                            camera.startPreview();
                            view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
                        }
                    });
        }
    });
}