Java Code Examples for android.opengl.GLSurfaceView#setRenderMode()

The following examples show how to use android.opengl.GLSurfaceView#setRenderMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From LearnOpenGL with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (!Utils.supportGlEs20(this)) {
        Toast.makeText(this, "GLES 2.0 not supported!", Toast.LENGTH_LONG).show();
        finish();
        return;
    }

    mGLSurfaceView = (GLSurfaceView) findViewById(R.id.surface);

    mGLSurfaceView.setEGLContextClientVersion(2);
    mRenderer = new DemoRenderer(this);
    mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    mGLSurfaceView.setRenderer(mRenderer);
    mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
}
 
Example 2
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.demo_opengl);
	view = (GLSurfaceView) findViewById(R.id.gl);

	getActionBar().setTitle(R.string.title_demo_heartrate);

	viewText = (TextView) findViewById(R.id.text);

	renderer = new PolygonRenderer(this);
	view.setRenderer(renderer);
	//view.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
	// Render when hear rate data is updated
	view.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
 
Example 3
Source File: TiledImageView.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
public TiledImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    if (!IS_SUPPORTED) {
        return;
    }

    mRenderer = new ImageRendererWrapper();
    mRenderer.image = new TiledImageRenderer(this);
    View view;
    if (USE_TEXTURE_VIEW) {
        mTextureView = new BlockingGLTextureView(context);
        mTextureView.setRenderer(new TileRenderer());
        view = mTextureView;
    } else {
        mGLSurfaceView = new GLSurfaceView(context);
        mGLSurfaceView.setEGLContextClientVersion(2);
        mGLSurfaceView.setRenderer(new TileRenderer());
        mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
        view = mGLSurfaceView;
    }
    addView(view, new LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    //setTileSource(new ColoredTiles());
}
 
Example 4
Source File: CameraCaptureActivity.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera_capture);

    File outputFile = new File(Environment.getExternalStorageDirectory(), "camera-test.mp4");

    // Define a handler that receives camera-control messages from other threads.  All calls
    // to Camera must be made on the same thread.  Note we create this before the renderer
    // thread, so we know the fully-constructed object will be visible.
    mCameraHandler = new CameraHandler(this);

    // Configure the GLSurfaceView.  This will start the Renderer thread, with an
    // appropriate EGL context.
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2);     // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, outputFile);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    Log.d(TAG, "onCreate complete: " + this);
}
 
Example 5
Source File: MainActivity.java    From AndroidPlayground with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mGlSurfaceView = (GLSurfaceView) findViewById(R.id.mGLSurfaceView);

    mGlSurfaceView.setEGLContextClientVersion(2);
    mRenderer = new MyRenderer(getResources());
    mGlSurfaceView.setRenderer(mRenderer);
    mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    mRendererSet = true;

    findViewById(R.id.mBtn).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            mRenderer.changePos();
            mGlSurfaceView.requestRender();
        }
    });
}
 
Example 6
Source File: PreviewTranscode.java    From media-for-mobile with Apache License 2.0 5 votes vote down vote up
public PreviewTranscode(GLSurfaceView glView,
                        IEglUtil eglUtil) {
    this.glView = glView;
    this.eglUtil = eglUtil;
    textureRender = new TextureRenderer(eglUtil);

    glView.setEGLContextClientVersion(2);
    glView.setEGLConfigChooser(true);
    glView.setRenderer(this);
    glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
 
Example 7
Source File: RtmpPublisher.java    From RtmpPublisher with Apache License 2.0 5 votes vote down vote up
RtmpPublisher(AppCompatActivity activity,
              GLSurfaceView glView,
              String url,
              int width,
              int height,
              int audioBitrate,
              int videoBitrate,
              CameraMode mode,
              PublisherListener listener) {

    activity.getLifecycle().addObserver(this);

    this.glView = glView;
    this.url = url;
    this.width = width;
    this.height = height;
    this.audioBitrate = audioBitrate;
    this.videoBitrate = videoBitrate;

    this.camera = new CameraClient(activity, mode);
    this.streamer = new Streamer();
    this.streamer.setMuxerListener(listener);

    glView.setEGLContextClientVersion(2);
    renderer = new CameraSurfaceRenderer();
    renderer.addOnRendererStateChangedLister(streamer.getVideoHandlerListener());
    renderer.addOnRendererStateChangedLister(this);

    glView.setRenderer(renderer);
    glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

}
 
Example 8
Source File: PreviewRender.java    From media-for-mobile with Apache License 2.0 5 votes vote down vote up
public PreviewRender(GLSurfaceView glView,
                     IEglUtil eglUtil,
                     Camera camera) {
    this.glView = glView;
    this.eglUtil = eglUtil;
    textureRender = new TextureRenderer(eglUtil);
    this.camera = camera;
    updateCameraParameters();

    glView.setEGLContextClientVersion(2);
    glView.setEGLConfigChooser(true);
    glView.setRenderer(this);
    glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
 
Example 9
Source File: MediaEffectsFragment.java    From android-MediaEffects with Apache License 2.0 5 votes vote down vote up
@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 {
        setCurrentEffect(R.id.none);
    }
}
 
Example 10
Source File: FlipViewController.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void setupSurfaceView(Context context) {
  surfaceView = new GLSurfaceView(getContext());

  cards = new FlipCards(this, flipOrientation == VERTICAL);
  renderer = new FlipRenderer(this, cards);

  surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
  surfaceView.setZOrderOnTop(true);
  surfaceView.setRenderer(renderer);
  surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
  surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

  addViewInLayout(surfaceView, -1, new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
                                                                LayoutParams.FILL_PARENT), false);
}
 
Example 11
Source File: FlipViewController.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void setupSurfaceView(Context context) {
  surfaceView = new GLSurfaceView(getContext());

  cards = new FlipCards(this, flipOrientation == VERTICAL);
  renderer = new FlipRenderer(this, cards);

  surfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
  surfaceView.setZOrderOnTop(true);
  surfaceView.setRenderer(renderer);
  surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
  surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

  addViewInLayout(surfaceView, -1, new AbsListView.LayoutParams(LayoutParams.FILL_PARENT,
                                                                LayoutParams.FILL_PARENT), false);
}
 
Example 12
Source File: EffectsFilterActivity.java    From ImageEffects with Eclipse Public License 1.0 5 votes vote down vote up
@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		/**
		 * Initialise the renderer and tell it to only render when Explicit
		 * 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);
		mCurrentEffect = R.id.none;
	}
 
Example 13
Source File: GameActivity.java    From Tanks with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);

  requestWindowFeature(Window.FEATURE_NO_TITLE);
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

  handler = new Handler();
  renderer = new Renderer();

  initializeContext();
  initializeFactory();

  // OpenGL init
  glView = new GLSurfaceView(this);
  glView.getHolder().setFormat(PixelFormat.RGBA_8888);
  glView.setEGLContextClientVersion(2);
  glView.setEGLConfigChooser(new ConfigChooser());
  glView.setRenderer(renderer);
  glView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

  // Bind listener
  glView.setOnTouchListener(this);

  // Set view
  setContentView(glView);

  // Set menu and world
  initializeContent();
}
 
Example 14
Source File: BroadcastActivity.java    From cineio-broadcast-android with MIT License 5 votes vote down vote up
private void initializeGLView() {
    // Configure the GLSurfaceView.  This will start the Renderer thread, with an
    // appropriate EGL context.
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2);     // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, sVideoEncoder, mMuxer);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
 
Example 15
Source File: CameraCaptureActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera_capture);

    File outputFile = new File(getFilesDir(), "camera-test.mp4");
    TextView fileText = (TextView) findViewById(R.id.cameraOutputFile_text);
    fileText.setText(outputFile.toString());

    Spinner spinner = (Spinner) findViewById(R.id.cameraFilter_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.cameraFilterNames, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner.
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(this);

    // Define a handler that receives camera-control messages from other threads.  All calls
    // to Camera must be made on the same thread.  Note we create this before the renderer
    // thread, so we know the fully-constructed object will be visible.
    mCameraHandler = new CameraHandler(this);

    mRecordingEnabled = sVideoEncoder.isRecording();

    // Configure the GLSurfaceView.  This will start the Renderer thread, with an
    // appropriate EGL context.
    mGLView = (GLSurfaceView) findViewById(R.id.cameraPreview_surfaceView);
    mGLView.setEGLContextClientVersion(2);     // select GLES 2.0
    mRenderer = new CameraSurfaceRenderer(mCameraHandler, sVideoEncoder, outputFile);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    Log.d(TAG, "onCreate complete: " + this);
}
 
Example 16
Source File: MainActivity.java    From Rocko-Android-Demos with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /**
     * Initialise the renderer and tell it to only render when
     * Explicit 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);
    mCurrentEffect = R.id.none;
}
 
Example 17
Source File: TiledImageView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
public TiledImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mRenderer = new ImageRendererWrapper();
    mRenderer.image = new TiledImageRenderer(this);
    mGLSurfaceView = new GLSurfaceView(context);
    mGLSurfaceView.setEGLContextClientVersion(2);
    mGLSurfaceView.setRenderer(new TileRenderer());
    mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    addView(mGLSurfaceView, new LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    //setTileSource(new ColoredTiles());
}
 
Example 18
Source File: VideoRendererGui.java    From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private VideoRendererGui(GLSurfaceView surface) {
  this.surface = surface;
  // Create an OpenGL ES 2.0 context.
  surface.setPreserveEGLContextOnPause(true);
  surface.setEGLContextClientVersion(2);
  surface.setRenderer(this);
  surface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

  yuvImageRenderers = new ArrayList<YuvImageRenderer>();
}
 
Example 19
Source File: VRPlayerActivity.java    From IjkVRPlayer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Uri uri = getIntent().getData();
    if (uri == null) {
        Toast.makeText(this, "no media file to open!", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    setContentView(R.layout.activity_vr_player);
    mGLView = (GLSurfaceView) findViewById(R.id.surface);
    mGLView.setEGLContextClientVersion(2); //GLES 2.0
    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                prepareMediaPlayerIfReady();
                return;
            } else if (msg.what == 2) {
                mGLView.requestRender();
            }
            super.handleMessage(msg);
        }
    };
    // TODO: implements your TextureRender
    mRenderer = new IjkVRRender(mHandler);
    mGLView.setRenderer(mRenderer);
    mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
    } else {
        initMediaPlayer(uri);
    }
}
 
Example 20
Source File: PointCloudActivity.java    From tango with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jpoint_cloud);
    setTitle(R.string.app_name);

    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);

    mSaveButton = (Button) findViewById(R.id.saveButton);
    mSaveButton.setOnClickListener(this);
    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);

    mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view);
    mGLView.setEGLContextClientVersion(2);

    mTango = new Tango(this);
    mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT);
    // tangoCameraPreview = (TangoCameraPreview) findViewById(R.id.cameraView);

    int maxDepthPoints = mConfig.getInt("max_point_cloud_elements");
    mRenderer = new PCRenderer(maxDepthPoints);
    mGLView.setRenderer(mRenderer);

    mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
    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;

    // Set up OpenGL ES surface
    mCamView = new GLSurfaceView(this);
    mCamView.setEGLContextClientVersion(2);
    mCamView.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR);
    mCamView.setRenderer(renderer_ = new FrameRenderer(this));
    mCamView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    mCamView.setOnClickListener(this);
    FrameLayout placeholder = (FrameLayout)findViewById(R.id.cameraFrame);
    placeholder.addView(mCamView);
    cameraTextures_ = new HashMap<>();
}