Transparent background for HelloWorld demo

Started by INeedMySpace, January 09, 2011, 05:05:31 AM

Previous topic - Next topic

INeedMySpace

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:
// 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

//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

EgonOlsen

Try to use a color with an alpha value instead.

INeedMySpace

Quote from: EgonOlsen on January 09, 2011, 10:37:07 AM
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

paulscode

This sounds similar to what dl.zerocool was doing on this thread.  Specifically, this may be related to your problem:
QuoteI 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.

INeedMySpace


QuoteI 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

INeedMySpace

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
QuoteChildren 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.
<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

arekz

INeedMySpace, did you succes reproduce transparent background in demo app?