OpenGL Background Transparency and Multiple Activities

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

OpenGL Background Transparency and Multiple Activities

Postby snowjumpstump » Wed Apr 14, 2010 6:10 pm

Hello all,

I have 3 activities:

Activity 1 - The main Activity (as far as the XML layout) has a text heading (ex. "Welcome!"), a gradient background image (for style), and has a "Submit" button that launches Activity 2.

Activity 2 - This activity has the same background image, and a different heading ("The Cube"). In the onCreate method, I have it start Activity 3.

Activity 3 - This activity has my openGL cube. Right now in the manifest, the theme has been set to TRANSLUCENT so that the 3D cube "appears" to be floating on top of Activity 2. This Activity also uses the MENU in order to close this Activity when a user selects it.

Unfortunately, when this "close" button is pressed, it closes Activity 3, and takes me back to Activity 2 which is essentially now a blank screen with the heading and background gradient. It does not take me back to Activity 1 (which is what I want).

My question is, should I have the openGL cube in a separate Activity (like it is now), or should I find a way to implement this cube into Activity 2?

If not, how can I go from Activity 3 back to Activity 1 when the user "closes" the openGL Activity?

The reason I have 3 Activities in the first place is because I cannot find another way to make just the background of the openGL transparent (so that it shows the underlying layout that includes the heading and the gradient background).

Thanks for the help!

-sjs-
snowjumpstump
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 14, 2010 5:50 pm

Top

Re: OpenGL Background Transparency and Multiple Activities

Postby mb_zi » Wed Apr 14, 2010 9:56 pm

surely you can do activity 2 and 3 together. render the background image onto a cube, same title and can use the menu system in the Opengl activity too. that way when you close the activity you go to act 1.
mb_zi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Feb 27, 2010 2:16 am

Postby snowjumpstump » Thu Apr 15, 2010 3:41 pm

Thanks for the reply, I am looking into that solution. I have included screen shots from the emulator to illustrate what is going on.

Also, if anyone has a better way to overlay openGL onto another activity with the openGL background being transparent, I am all ears.

Thanks again!

-sjs-
Attachments
help_act1.jpg
Activity 1 - Simple, just press "Submit" to launch Activity 2 (which onCreate launches Activity 3).
help_act1.jpg (97.68 KiB) Viewed 3928 times
help_act2.jpg
Activity 2 - This is all that Activity 2 is. This is what displays after I "close" Activity 3. I don't want to go here, I want to go back to Activity 1...essentially closing both Activity 3 AND Activity 2.
help_act2.jpg (97.15 KiB) Viewed 3928 times
help_act3.jpg
This is Activity 3. Here you can see the 3D cube openGL is overlayed on top of Activity 2. Is there a way to just combine these 2 activities and achieve the same result?
help_act3.jpg (97.33 KiB) Viewed 3928 times
snowjumpstump
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 14, 2010 5:50 pm

Postby snowjumpstump » Thu Apr 22, 2010 6:41 pm

Hello all,

Well I have been researching this thoroughly and I cannot seem to come up with a solution.

I've realized now that this is an OpenGL problem and not an Android problem. The way that I was achieving this before was "faking" the effect. I was making the ENTIRE activity TRANSLUCENT in the Android Manifest file (ex. android:theme="@android:style/Theme.Translucent.NoTitleBar").

By doing this, I was making Activity 3 translucent while Activity 2 was still running, thereby creating the illusion that Activity 3 was "hovering" over Activity 2.

That's not what I want to do. I want it to be one single activity.

On various forums, there are a couple of suggestions, none of which achieve what I am trying to do:

Method 1: Draw a full-screen quad that has the background image (in my case the gradient) applied to it as a texture map. Don't want to do this, would rather use my RelativeLayout XML which has android:background="@drawable/all_bggradient" already specified. And I know that adding another object and applying textures adds more code.

Method 2: Use a combination of the GL_BLEND function implementing GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA and setting glClearColor to 0,0,0,0. Unfortunately it seems that this method effects only my cube (foreground) object, and not the background. I want to clear to an image NOT a color.

Method 3: Create a new RelativeLayout, add the GLSurfaceView as the first child, and then add all other views AFTER this view. This method will stack all of the other views on top of the GLSurfaceView. Again, good suggestion however I want my background image to appear BELOW the OpenGL cube and every other view.

So basically I am stuck. Does anyone know if there is a better way to do this? Reiterating, I want to have ONLY a 3D cube rotate on my screen and NOT have ANY background color. I want the OpenGL background to transparent.

Thanks in advance for any help.

-sjs-
snowjumpstump
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 14, 2010 5:50 pm

Postby snowjumpstump » Wed May 05, 2010 7:18 pm

Hello again all,

After even more searching around, I've decided that the best option to achieve what I am after is to draw a background quad (2 triangles) and texture map my image onto it.

I have set up a new class like in the TriangleRenderer example.

How can I set my quad to be the EXACT size of the window in BOTH Portrait and Landscape mode?

Also, what property should I be using (or manipulate) in order to "tile" my image just a single time? Right now it seems that in the example, my image is being tiled in the X direction 3 times.

I basically want my image and quad to fit exactly to the dimensions of the screen, regardless of orientation.

Thanks for the help!

-sjs-
snowjumpstump
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 14, 2010 5:50 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: Google [Bot] and 2 guests