opengl game with activities as menues

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

opengl game with activities as menues

Postby jumpoutofatree » Wed Mar 31, 2010 4:30 pm

So just a quick question. I'm writing an android opengl based game with a group at school. Is it bad practice in opengl to start activities based on xml layouts for menus such as main menu/pause, granted you flag to reorder or something to not recreating activities? One guy wants to create opengl menus and i argue that creating xml layouts is the easiest way so long you don't keep recreating the activity? Any input appreciated.

-Rob
jumpoutofatree
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Mar 23, 2010 4:48 pm
Location: Gainesville, Florida

Top

Postby MichaelEGR » Wed Mar 31, 2010 10:42 pm

For a school project and for apps that are going to be Android only then going the Activity dialog route is fine and much faster. Just add this to AndroidManifest for the Activity definition:
android:theme="@style/Theme.Typhon_Dialog"

The nice thing is that the Activity will display on top of the GL Activity and not destroy the GL context. So once the dialog Activity is dismissed the GL app pops back to life.

If this was a cross platform app then of course going the GL menu route is required.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Postby MichaelEGR » Wed Mar 31, 2010 10:47 pm

oops.. It seems I linked to a custom resource name "Theme.Typhon_Dialog" and not an Android default one. Here is what I use to display an Activity dialog over a GL context. Put this or something similar in an XML file in values resource directory.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.    <style name="Theme.Typhon_Dialog" parent="@android:style/Theme.Dialog">
  3.  
  4.       <item name="android:windowFrame">@null</item>
  5.  
  6.       <item name="android:windowNoTitle">true</item>
  7.  
  8.       <item name="android:windowIsFloating">true</item>
  9.  
  10.       <item name="android:windowContentOverlay">@null</item>
  11.  
  12.       <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
  13.  
  14.       <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
  15.  
  16.    </style>
  17.  
  18.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Postby jumpoutofatree » Thu Apr 01, 2010 2:18 am

AWESOME! ty very much.
jumpoutofatree
Junior Developer
Junior Developer
 
Posts: 17
Joined: Tue Mar 23, 2010 4:48 pm
Location: Gainesville, Florida

Re: opengl game with activities as menues

Postby 3-S-E » Sat Jun 25, 2011 7:28 pm

Thank you very much for sharing your solution with us!

I want to add the information, that if you want to start a new activity from outside the main activity, you have to add

Code: Select all
Intent.FLAG_ACTIVITY_NEW_TASK


to your Intent.

A possible call could like like this:

Code: Select all
Intent intent = new Intent(context, NewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);


I have forwarded the application context through all my classes and stored it in the field "context".
Is there any way to get the application context dynamically respectively to perform a call to "getApplicationContext()" from anywhere of the project?

Edit: Another question that I have is: Is it possible to make the new activity translucent / transparent, so that you can see the OpenGL-Surface beneath it?
3-S-E
Freshman
Freshman
 
Posts: 2
Joined: Sat Jun 25, 2011 6:52 pm

Re: opengl game with activities as menues

Postby MichaelEGR » Sun Jun 26, 2011 1:58 am

Is it possible to make the new activity translucent / transparent, so that you can see the OpenGL-Surface beneath it?


It should be with a few more theme stylings. This SO post discusses it though I've not verified / tested:
http://stackoverflow.com/questions/2176 ... in-android

Is there any way to get the application context dynamically respectively to perform a call to "getApplicationContext()" from anywhere of the project?


Any Context including an Activity can call the "getApplicationContext()" method of Context. If you are referring to code that is part of an Activity, but doesn't have access to a reference to the Activity then it's not directly possible.

A somewhat unclean way of providing the ability to get the application context anywhere without reference to a Context / Activity, etc is to create a static reference similar to a singleton that is initialized either in a custom Application or perhaps in each of your Activities onCreate() method.

Code: Select all
import android.content.Context;

public abstract class StaticApplicationContext
{
   private static Context appContext;

   public static Context get()
   {
      return appContext;
   }
   
   public static void set(Context newAppContext)
   {
      if (appContext == null)
         appContext = newAppContext;
   } 
}


Then either in a custom Application or the onCreate method of _all_ of your Activities initialize it:

Code: Select all
if (StaticApplicationContext.get() == null)
   StaticApplicationContext.set(getApplicationContext());


I mention initializing the static holder in each Activity in the case that your app has multiple entry points via intent filters. I suppose technically if that is not the case you'd only have to initialize it in the Activity marked as the main / launcher Activity though to be safe it wouldn't hurt including the initializer in each of your Activities to be sure there is a valid stored application context.

I mention this is kind of "unclean" as I at least avoid the above since a lot of my dev is cross-platform and I avoid static factories and / or singleton like constructs.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Re: opengl game with activities as menues

Postby 3-S-E » Sun Jun 26, 2011 9:27 am

MichaelEGR wrote:
Is it possible to make the new activity translucent / transparent, so that you can see the OpenGL-Surface beneath it?


It should be with a few more theme stylings. This SO post discusses it though I've not verified / tested:
http://stackoverflow.com/questions/2176 ... in-android


Thank you! I've found this SO post yesterday by myself and played with the styles for hours without a satisfying result. Five minutes ago I've switched just for fun from my honeycomb-tablet to my gingerbread-phone and run my app there... with (!!!) a transparent activity background as wished! :roll: Damn inconsistency...

@context: Thank you for sharing your information on this topic. :D
3-S-E
Freshman
Freshman
 
Posts: 2
Joined: Sat Jun 25, 2011 6:52 pm

Re: opengl game with activities as menues

Postby MichaelEGR » Mon Jun 27, 2011 4:58 am

Thank you! I've found this SO post yesterday by myself and played with the styles for hours without a satisfying result. Five minutes ago I've switched just for fun from my honeycomb-tablet to my gingerbread-phone and run my app there... with (!!!) a transparent activity background as wished! Damn inconsistency...


No doubt. I found one major bug in Honeycomb that took me ~45 hours to pinpoint and it was an immutable endian swap in the NIO API; big G fixed it immediately, but it didn't get into the 3.1 update! So yeah they rushed it and it's a bummer to hear that theming may be incompatible too. :: sigh ::

Perhaps post any solutions you find for Honeycomb in this thread, so when others search they can find it too. I'd be glad to hear of any solutions since I'm not immediately diving into this area, but would like transparent Activities for Honeycomb+.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

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

Who is online

Users browsing this forum: No registered users and 2 guests