Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Google Android

transparent background (setBackgroundOpacity)  [SOLVED]

Google Play Store, Amazon Kindle, Nook, and so many more

transparent background (setBackgroundOpacity)

Postby MoBill » 19 Feb 2012, 13:46

I am developing an android application where i need to make the shiva scene have a transparent background. I am exporting my shiva application as an android project so that i can do various things in the android sdk. I want to add a view behind my S3DSurfaceView and have it show through the S3DSurfaceView. I have tried using "scene.setBackgroundOpacity(hScene, 0)". I saw that in the following post:

http://www.stonetrip.com/developer/forum/viewtopic.php?f=43&t=23463&p=34760&hilit=setBackgroundOpacity#p34760

But that doesn't seem to work. Are there any other settings i need to set for this to work properly? Am i missing something? It seems like it should be simple, but isn't working.

Any advice would be greatly appreciated.

Thanks,
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)

Postby NiCoX » 19 Feb 2012, 13:53

Hi,

For this to work you need to check the UAT flag "use 32 bits color buffer". Did you?
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5642
Location: France

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 19 Feb 2012, 14:16

Hi NiCox,

Yes, i do have that setting checked.

Thanks,
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 20 Feb 2012, 16:04

Hi NiCox,

I tried creating a simple application and recreating everything from scratch to produce a transparent background and it still does not work. I followed the following steps:

1. Create a new project
2. Create a new game
3. Create a new scene
4. Create a new MainAI with the following:

function transparentBackgroundMainAI.onInit ( )
--------------------------------------------------------------------------------

application.setCurrentUserScene ( "transparentBackgroundScene" )
local hScene = application.getCurrentUserScene ( )
scene.setBackgroundOpacity ( hScene, 0 )
--------------------------------------------------------------------------------
end

5. Export the game as an android project
6. Author the project as an android "Project". I left all the default settings (Use OpenGLES1.1, User 32 bits color buffer, Use stencil buffer, install on connected device) all set to true.
7. Imported the android project in eclipse
8. Added a Button to the parent layout (oViewGroup).

And no luck, i don't see my button.

If i remove the 3d view (o3DView) i see the button. So it is there. But when the (o3DView) is added i don't see the button. I also verified in "initOpenGLES" that this.getHolder().setFormat(PixelFormat.TRANSLUCENT); is being called. I tried a few other things like setting the background of the various view to transparent color, but nothing seems to work. Any ideas? Is anyone able to get this to work?

Thanks again for any assistance.
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 24 Feb 2012, 14:58

Has anyone had any success with this on the android platform? Can anyone from Shiva either verify that it does work or if it is a bug? Anyone.... Pleeeaaaasssseeee!!!
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)

Postby Yopia » 05 Mar 2012, 11:21

Hi

Could you try to use a 16 bits color buffer and translucent pixel format ?

to do that modify in S3DSurfaceView.java the function initOpenGLES :

write _bWant32bpp = false ; at the begining to use 565 buffer format
and
comment the both : //if ( iPreferedAlphaSize > 0 ) to force setFormat ( PixelFormat.TRANSLUCENT )
User avatar
Yopia
Platinum Boarder
Platinum Boarder
 
Posts: 630

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 05 Mar 2012, 15:36

Hi Yopia,

I tried what you recommended and it still doesn't work. Have you seen this work before on an android device?

Thanks,
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 10 Mar 2012, 16:13

Anybody?? Please?? Has anyone seen this work on an android device? In theory, it should be very easy to implement and test. Can anyone confirm that they CAN or CANNOT get this to work. This is very frustrating.
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15


Re: transparent background (setBackgroundOpacity)

Postby MoBill » 14 Mar 2012, 02:59

I am able to get a transparent background to work on a non-shiva opengl implementation. I am able to render stuff and see my background view. But when i apply the same settings to the shiva version, it doesn't work. If i comment out the "engineRunOneFrame" call in the "onDrawFrame" method, i can see the background. But of course nothing gets drawn. Does this add any insight?
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)  [SOLVED]

Postby NiCoX » 14 Mar 2012, 09:59

Hi,

What is sure is that you need this line (for instance in the MSG_ENGINE_RESUME event):

Code: Select all
o3DView.setZOrderOnTop ( true ) ;


Using that, and not hiding the splashsceen make 3DView and SplashView to be blended together. But the order is incorrect. Seems to be a ViewGroup limitation (according to some threads I found on the web). I'm investigating...

Anyways, you can be sure the engine is properly clearing alpha channel of the render target.
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5642
Location: France

Re: transparent background (setBackgroundOpacity)

Postby NiCoX » 14 Mar 2012, 13:27

If i comment out the "engineRunOneFrame" call in the "onDrawFrame" method, i can see the background.

If you call:

Code: Select all
GLES20.glClearColor ( 1, 0, 0, 0 ) ;
GLES20.glClear ( GLES20.GL_COLOR_BUFFER_BIT ) ;

In the onDrawFrame method (not calling the engineRunOneFrame), does it work for you? Because for me it doesn't work either... so my guess is that the problem is not in the engine itself (and I double checked the values, I confirm the engine is clearing/rendering with the right alpha values (and it works on iOS with the same code)), but in the "Android shell"...
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5642
Location: France

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 14 Mar 2012, 14:29

I was able to get the background to show after commenting out "engineRunOneFrame". But there were also other steps that i did as well. I added

Code: Select all
o3DView.setZOrderOnTop ( true );


like your recommended and I also replaced the whole "initOpenGLES" function. I have to set that up again and i will let you know the steps to get that to work. It may not be the engine per say, but maybe some other things that are happening in the other native code that "engineRunOneFrame" calls.
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Re: transparent background (setBackgroundOpacity)

Postby NiCoX » 14 Mar 2012, 14:47

Yes I also tried to replace the "initOpenGLES" function (for info prior to Android 2.2 this was required to initialize OpenGL ES 2.0), using "o3DView.setZOrderOnTop", but with no luck. I was also able to get the 3D render blended with a background image (the splash screen in my case, just commented the line hiding it), but not in the correct way (splash screen was *over* the 3D view, though the zorder was ok)...

I also tried without a ViewGroup, using "setContentView" with the SplashView then using "addContentView" for the 3DView, again that was not working as expected.

Honestly I think the solution is just a flag to turn on or "a way to do things" (eg. declaring the 3D view in the XML instead of creating it from code), but could not find it :(
User avatar
NiCoX
Platinum Boarder
Platinum Boarder
 
Posts: 5642
Location: France

Re: transparent background (setBackgroundOpacity)

Postby MoBill » 14 Mar 2012, 15:30

i can get it to work without calling "engineRunOneFrame" in the "onDrawFrame" method. The following are the steps.

1. Keep initOpenGLES but insure that it is called as follows

Code: Select all
initOpenGLES ( false, true, true );


2. in MSG_START_ENGINE do the following. Insure that setZOrderOnTop happens before it is added to the group

Code: Select all
o3DView.setZOrderOnTop(true);
oViewGroup.addView ( o3DView ) ;


3. in "onDrawFrame" get rid of the all the shiva code and call

Code: Select all
gl.glClearColor(0.1f, 0.1f, 0.9f, 0.3f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);


That worked for me. But again, as soon as i add the call to "engineRunOneFrame" it doesn't work anymore.

Thoughts?
MoBill
Fresh Boarder
Fresh Boarder
 
Posts: 15

Next

Return to Google Android