Author Topic: Transparent background for HelloWorld demo  (Read 4937 times)

Offline INeedMySpace

  • byte
  • *
  • Posts: 9
    • View Profile
Transparent background for HelloWorld demo
« on: January 09, 2011, 05:05:31 am »
Hello guys.
I`m bit curious about JPCT-AE capabilities and started from small modification of HelloWorld example.
My goal was to setup transparent background for this demo. I tried some ways I found on this forum but still can`t reach my goal. I still have no transparent background.
Need you help. Here is some code modifications:
Code: [Select]
// in onCreate
super.onCreate(savedInstanceState);

getWindow().setFormat(PixelFormat.TRANSLUCENT);

mGLView = new GLSurfaceView(getApplication());

// 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];
// }
// });
mGLView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
mGLView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
setContentView(mGLView);
and also I have changed back color
Code: [Select]
//private RGBColor back = new RGBColor(50, 50, 100);
private RGBColor back = new RGBColor(0, 0, 0, 0);
Background is black and nothing is seen under. Have I missed some important point?
Thanks in advance for any hints.
Right here, right now ...or later in some other place

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Transparent background for HelloWorld demo
« Reply #1 on: January 09, 2011, 10:37:07 am »
Try to use a color with an alpha value instead.

Offline INeedMySpace

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Transparent background for HelloWorld demo
« Reply #2 on: January 09, 2011, 08:34:24 pm »
Try to use a color with an alpha value instead.
Egon, sorry, but I`m still confused. As I see in javadocs RGBColor:
public RGBColor(int r, int g, int b, int a) - Creates a new color with alpha.

Parameters:
r - red value between 0 and 255
g - green value between 0 and 255
b - blue value between 0 and 255
a - alpha value between 0 and 255

So private RGBColor back = new RGBColor(0, 0, 0, 0); will give me color with alpha 0 (fully transparent color). I used it in my example already. Clearing FrameBuffer with this color - fb.clear(back);
Do you mean something else?
Right here, right now ...or later in some other place

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Transparent background for HelloWorld demo
« Reply #3 on: January 10, 2011, 12:24:47 am »
This sounds similar to what dl.zerocool was doing on this thread.  Specifically, this may be related to your problem:
Quote
I create a new camera and I give a render to my glSurfaceView
and of course set the Translucent window  (8888) pixel format and depth buffer to it.
(Without that your glSurfaceView will not support alpha channel and you will not see the camera layer.)

I've not done anything like this myself, so I don't know if this is helpful or not.

Offline INeedMySpace

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Transparent background for HelloWorld demo
« Reply #4 on: January 10, 2011, 01:58:10 am »

Quote
I create a new camera and I give a render to my glSurfaceView
and of course set the Translucent window  (8888) pixel format and depth buffer to it.
(Without that your glSurfaceView will not support alpha channel and you will not see the camera layer.)

Yeah, I were trying to simplify example with glsurface and camera - something like Android API Demos http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/TranslucentGLSurfaceViewActivity.html but with JPCT-AE.
In my example it seems I don't forget all important steps:
- getWindow().setFormat(PixelFormat.TRANSLUCENT);
- mGLView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
- mGLView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
- private RGBColor back = new RGBColor(0, 0, 0, 0); // color with alpha 0 (should be transparent as I understand)
Right here, right now ...or later in some other place

Offline INeedMySpace

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Transparent background for HelloWorld demo
« Reply #5 on: January 10, 2011, 03:42:34 am »
Very interesting - I assembled example with both glsurfaceview and surfaceview for camera as was described in dl.zerocool thread and it works :) Something i still can't understand from android reference FrameLayout
Quote
Children are drawn in a stack, with the most recently added child on top.
But it works well only with this layout - glsurfaceview first and surfaceview second. If you change order only camera preview will be seen.  As I understand order should be changed according to docs - grrr google.
Code: [Select]
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.opengl.GLSurfaceView
android:id="@+id/GLSURFACEVIEW"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<SurfaceView
android:id="@+id/CAMERAVIEW"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:keepScreenOn="true"/>
</FrameLayout>

But still I want to reproduce simple demo with JPCT-AE like TranslucentGLSurfaceActivity from google api demos.
Right here, right now ...or later in some other place

Offline arekz

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Transparent background for HelloWorld demo
« Reply #6 on: July 08, 2016, 11:01:44 am »
INeedMySpace, did you succes reproduce transparent background in demo app?