jPCT-AE - a 3d engine for Android => Support => Topic started by: nnyerges on September 30, 2014, 04:58:08 pm

Title: EGLConfigChooser & Transparent Backgrounds help
Post by: nnyerges on September 30, 2014, 04:58:08 pm

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

mGLView.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
Title: Re: EGLConfigChooser & Transparent Backgrounds help
Post by: EgonOlsen on September 30, 2014, 08:39:02 pm
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 (http://www.jpct.net/forum2/index.php?topic=1884.0)?
Title: Re: EGLConfigChooser & Transparent Backgrounds help
Post by: nnyerges on October 01, 2014, 05:29:27 pm
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) {
   if (master != null) {

   myWidth =1280;
   myHeight =800;
   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);

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

   this.setContentView(fl, flp);


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

         if (touchTurn != 0) {
            touchTurn = 0;
         if (touchTurnUp != 0) {
            touchTurnUp = 0;

         // 2D Redraw

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