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

The following examples show how to use android.opengl.GLSurfaceView#setEGLConfigChooser() . 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: TranslucentGLSurfaceViewActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create our Preview view and set it as the content of our
    // Activity
    mGLSurfaceView = new GLSurfaceView(this);
    // We want an 8888 pixel format because that's required for
    // a translucent window.
    // And we want a depth buffer.
    mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    // Tell the cube renderer that we want to render a translucent version
    // of the cube:
    mGLSurfaceView.setRenderer(new CubeRenderer(true));
    // Use a surface format with an Alpha channel:
    mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    setContentView(mGLSurfaceView);
}
 
Example 2
Source File: VrShellImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@UsedByReflection("VrShellDelegate.java")
public VrShellImpl(Activity activity) {
    super(activity);
    mActivity = activity;
    mContentViewCoreContainer = new FrameLayout(getContext()) {
        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            return true;
        }
    };
    addView(mContentViewCoreContainer, 0, new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT));
    mGlSurfaceView = new GLSurfaceView(getContext());
    mGlSurfaceView.setEGLContextClientVersion(2);
    mGlSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 0, 0);
    mGlSurfaceView.setPreserveEGLContextOnPause(true);
    mGlSurfaceView.setRenderer(this);
    setPresentationView(mGlSurfaceView);

    if (setAsyncReprojectionEnabled(true)) {
        AndroidCompat.setSustainedPerformanceMode(mActivity, true);
    }
}
 
Example 3
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 4
Source File: Game.java    From PD-classes with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate( Bundle savedInstanceState ) {
	super.onCreate( savedInstanceState );
	
	BitmapCache.context = TextureCache.context = instance = this;
	
	DisplayMetrics m = new DisplayMetrics();
	getWindowManager().getDefaultDisplay().getMetrics( m );
	density = m.density;
	
	try {
		version = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionName;
	} catch (NameNotFoundException e) {
		version = "???";
	}
	
	setVolumeControlStream( AudioManager.STREAM_MUSIC );
	
	view = new GLSurfaceView( this );
	view.setEGLContextClientVersion( 2 );
	view.setEGLConfigChooser( false );
	view.setRenderer( this );
	view.setOnTouchListener( this );
	setContentView( view );
}
 
Example 5
Source File: Game.java    From YetAnotherPixelDungeon with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate( Bundle savedInstanceState ) {
	super.onCreate( savedInstanceState );
	
	BitmapCache.context = TextureCache.context = instance = this;
	
	DisplayMetrics m = new DisplayMetrics();
	getWindowManager().getDefaultDisplay().getMetrics( m );
	density = m.density;
	
	try {
		version = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionName;
		versionNum = getPackageManager().getPackageInfo( getPackageName(), 0 ).versionCode;
	} catch (NameNotFoundException e) {
		version = "???";
           versionNum = 0;
	}
	
	setVolumeControlStream( AudioManager.STREAM_MUSIC );
	
	view = new GLSurfaceView( this );
	view.setEGLContextClientVersion( 2 );
	view.setEGLConfigChooser( false );
	view.setRenderer( this );
	view.setOnTouchListener( this );
	setContentView( view );
}
 
Example 6
Source File: OpenGlDemo.java    From opengl with Apache License 2.0 5 votes vote down vote up
/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
GLSurfaceView view = new GLSurfaceView(this);
      view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);  //fix for no config error, but no idea what it does.
 		view.setRenderer(new OpenGLRenderer());
 		setContentView(view);
  }
 
Example 7
Source File: SolarSystemActivity.java    From opengl with Apache License 2.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
 		GLSurfaceView view = new GLSurfaceView(this);
        view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
   		view.setRenderer(new SolarSystemRenderer());
   		setContentView(view);
}
 
Example 8
Source File: OpenGlDemo1Activity.java    From opengl with Apache License 2.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    		WindowManager.LayoutParams.FLAG_FULLSCREEN);
    GLSurfaceView view = new GLSurfaceView(this);
    view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);  //fix config error, but no idea what this does.
    view.setRenderer(new SquareRenderer(true));
    setContentView(view);
}
 
Example 9
Source File: BouncyCubeActivity.java    From opengl with Apache License 2.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
 		GLSurfaceView view = new GLSurfaceView(this);
        view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);  //fix No config chosen error.  No idea what this actually does though.
   		view.setRenderer(new BouncyCubeRenderer(true));
   		setContentView(view);
}
 
Example 10
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 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: 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 13
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 14
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 15
Source File: CompressedTextureActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mGLView = new GLSurfaceView(this);
    mGLView.setEGLConfigChooser(false);
    StaticTriangleRenderer.TextureLoader loader;
    if (TEST_CREATE_TEXTURE) {
        loader = new SyntheticCompressedTextureLoader();
    } else {
        loader = new CompressedTextureLoader();
    }
    mGLView.setRenderer(new StaticTriangleRenderer(this, loader));
    setContentView(mGLView);
}
 
Example 16
Source File: OGLESContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * <code>createView</code> creates the GLSurfaceView that the renderer will
 * draw to. <p> The result GLSurfaceView will receive input events and
 * forward them to the Application. Any rendering will be done into the
 * GLSurfaceView. Only one GLSurfaceView can be created at this time. The
 * given configType specifies how to determine the display configuration.
 *
 * @return GLSurfaceView The newly created view
 */
public GLSurfaceView createView(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ConfigurationInfo info = am.getDeviceConfigurationInfo();
    // NOTE: We assume all ICS devices have OpenGL ES 2.0.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // below 4.0, check OpenGL ES 2.0 support.
        if (info.reqGlEsVersion < 0x20000) {
            throw new UnsupportedOperationException("OpenGL ES 2.0 or better is not supported on this device");
        }
    } else if (Build.VERSION.SDK_INT < 9){
        throw new UnsupportedOperationException("jME3 requires Android 2.3 or later");
    }

    // Start to set up the view
    GLSurfaceView view = new GLSurfaceView(context);
    logger.log(Level.INFO, "Android Build Version: {0}", Build.VERSION.SDK_INT);
    if (androidInput == null) {
        if (Build.VERSION.SDK_INT >= 14) {
            androidInput = new AndroidInputHandler14();
        } else if (Build.VERSION.SDK_INT >= 9){
            androidInput = new AndroidInputHandler();
        }
    }
    androidInput.setView(view);
    androidInput.loadSettings(settings);

    // setEGLContextClientVersion must be set before calling setRenderer
    // this means it cannot be set in AndroidConfigChooser (too late)
    // use proper openGL ES version
    view.setEGLContextClientVersion(info.reqGlEsVersion>>16);

    view.setFocusableInTouchMode(true);
    view.setFocusable(true);

    // setFormat must be set before AndroidConfigChooser is called by the surfaceview.
    // if setFormat is called after ConfigChooser is called, then execution
    // stops at the setFormat call without a crash.
    // We look at the user setting for alpha bits and set the surfaceview
    // PixelFormat to either Opaque, Transparent, or Translucent.
    // ConfigChooser will do its best to honor the alpha requested by the user
    // For best rendering performance, use Opaque (alpha bits = 0).
    int curAlphaBits = settings.getAlphaBits();
    logger.log(Level.FINE, "curAlphaBits: {0}", curAlphaBits);
    if (curAlphaBits >= 8) {
        logger.log(Level.FINE, "Pixel Format: TRANSLUCENT");
        view.getHolder().setFormat(PixelFormat.TRANSLUCENT);
        view.setZOrderOnTop(true);
    } else if (curAlphaBits >= 1) {
        logger.log(Level.FINE, "Pixel Format: TRANSPARENT");
        view.getHolder().setFormat(PixelFormat.TRANSPARENT);
    } else {
        logger.log(Level.FINE, "Pixel Format: OPAQUE");
        view.getHolder().setFormat(PixelFormat.OPAQUE);
    }

    AndroidConfigChooser configChooser = new AndroidConfigChooser(settings);
    view.setEGLConfigChooser(configChooser);
    view.setRenderer(this);

    // Attempt to preserve the EGL Context on app pause/resume.
    // Not destroying and recreating the EGL context
    // will help with resume time by reusing the existing context to avoid
    // reloading all the OpenGL objects.
    if (Build.VERSION.SDK_INT >= 11) {
        view.setPreserveEGLContextOnPause(true);
    }

    return view;
}
 
Example 17
Source File: MainActivity.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setImmersiveSticky();
  getWindow()
      .getDecorView()
      .setOnSystemUiVisibilityChangeListener(
          new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
              if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                setImmersiveSticky();
              }
            }
          });

  // Enable VR mode, if the device supports it.
  AndroidCompat.setVrModeEnabled(this, true);

  // Get the GvrLayout.
  gvrLayout = new GvrLayout(this);

  // Enable scan line racing, if possible.
  if (gvrLayout.setAsyncReprojectionEnabled(true)) {
    Log.d(TAG, "Successfully enabled scanline racing.");
    // Scanline racing decouples the app framerate from the display framerate,
    // allowing immersive interaction even at the throttled clockrates set by
    // sustained performance mode.
    AndroidCompat.setSustainedPerformanceMode(this, true);
  } else {
    Log.w(TAG, "Failed to enable scanline racing.");
  }

  // Configure the GLSurfaceView.
  surfaceView = new GLSurfaceView(this);
  surfaceView.setEGLContextClientVersion(2);
  surfaceView.setEGLConfigChooser(8, 8, 8, 0, 0, 0);
  surfaceView.setPreserveEGLContextOnPause(true);
  surfaceView.setRenderer(renderer);

  // Set the GLSurfaceView as the GvrLayout's presentation view.
  gvrLayout.setPresentationView(surfaceView);

  // Enable and configure the back button in the UI layout.
  gvrLayout
      .getUiLayout()
      .setBackButtonListener(
          new Runnable() {
            @Override
            public void run() {
              onBackPressed();
            }
          });

  // Add the GvrLayout to the View hierarchy.
  setContentView(gvrLayout);

  assetManager = getResources().getAssets();

  nativeOnCreate(assetManager, gvrLayout.getGvrApi().getNativeGvrContext());

  // Prevent screen from dimming/locking.
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}