EGLConfigChooser & Transparent Backgrounds help

Started by nnyerges, September 30, 2014, 04:58:08 PM

Previous topic - Next topic

nnyerges

Hi

1. I'm trying to understand the following line code on "HelloWorld-AE" example:


QuotemGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
   public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
   // Ensure that we get a 16bit framebuffer. Otherwise, we'll fall
   // back to Pixelflinger on some device (read: Samsung I7500)
   int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
   EGLConfig[] configs = new EGLConfig[1];
   int[] result = new int[1];
   egl.eglChooseConfig(display, attributes, configs, 1, result);
   return configs[0];
   }
});

1.1 How it works?. Its a complicate method to setup EGL configuration.
1.2 Why not use setEGLConfigChooser(8, 8, 8, 8, 16, 0) instead ?


2. I have read all jPCT's and all internet post's, about making the 3D surface background transparent .I Try all methods and combinations, without results.

2.1 Does somebody have successfully place a normal 2D SurfaceView behind a 3D GLSurfaceView?

Thanks in advance

EgonOlsen

That way of doing it was the only possible way to convince the Samsung i7500 device to use it's hardware for rendering. The easy way, albeit one might think that it's the same, didn't work. At least not back then. Today, this is more or less a relic. You can still use it and it shouldn't hurt but all it gives you is compatibility with an ancient device running under Android 1.6

Concerning the transparency: I never tried it myself, but there should be working examples in the forum. Maybe this helps: http://www.jpct.net/forum2/index.php?topic=1884.0?

nnyerges

#2
After making several attempts and changing the order of commands and views, I got the transparent background of mGLView. Using parent FrameLayout (fl) and two childs: a second FrameLayout (mbView) and (mGLView) in that order. Important to force mGLView.setZOrderOnTop (true) and not to forget to clear the frambuffer to an alpha RGBColor color (0, 0, 0, 0). This is an example:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
   if (master != null) {
      copy(master);
   }

   myWidth =1280;
   myHeight =800;

   requestWindowFeature(Window.FEATURE_NO_TITLE);
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
   boolean isPortrait = getResources().getConfiguration().orientation ==  Configuration.ORIENTATION_PORTRIT;
   int frameBufferWidth = isPortrait ? myHeight : myWidth;
   int frameBufferHeight = isPortrait ? myWidth : myHeight;
   Bitmap frameBuffer = Bitmap.createBitmap(frameBufferWidth, frameBufferHeight, Config.RGB_565); // for mbView
   scaleX = (float) frameBufferWidth / getWindowManager().getDefaultDisplay().getWidth();
   scaleY = (float) frameBufferHeight / getWindowManager().getDefaultDisplay().getHeight();

   FrameLayout fl = new FrameLayout(this);
   FrameLayout.LayoutParams flp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);

               mbView = new FrameLayout(this);
   fl.addView(mbView);

   mGLView = new GLSurfaceView(this);
   mGLView.setZOrderOnTop(true);
   mGLView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
   mGLView.getHolder().setFormat(PixelFormat.TRANSLUCENT);   renderer = new RendererCarpa();
   mGLView.setRenderer(renderer);
   
   fl.addView(mGLView);

   this.setContentView(fl, flp);
}


.............

      @Override
      public void onDrawFrame(GL10 arg0) {
         // TODO Auto-generated method stub

         if (touchTurn != 0) {
            carpa.rotateY(touchTurn);
            touchTurn = 0;
         }
         if (touchTurnUp != 0) {
            carpa.rotateX(touchTurnUp);
            touchTurnUp = 0;
         }

         // 2D Redraw

         // 3D Redraw
         fb.clear(transp);  // where transp = RGBColor transp = new RGBColor(0, 0, 0, 0)
         world.renderScene(fb);
         world.draw(fb);
         fb.display();

      }