File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Mixing Android GUI controls with game graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Mixing Android GUI controls with game graphics" Watch "Mixing Android GUI controls with game graphics" New topic
Author

Mixing Android GUI controls with game graphics

Augusto Sellhorn
Ranch Hand

Joined: May 24, 2007
Posts: 57
Is it possible to use Android GUI controls (buttons, labels, text fields, etc) on top of game graphics? For example; let's say I have an OpenGL drawn scene and want to popup a quit confirmation dialog? (the graphics a really on the box in that case)

What about rendering controls in the actual OpenGL or 2D graphics scene, for example a free floating button or text field in the middle of the screen.

The reason I'm asking is that in the desktop world, gaming engines usually have their own Game UI control libraries. Now, in Java2D/Swing it was possible to do some of this because the Swing controls are lightweight. I'm not sure if the Android controls are lightweight or not, so wondering if you guys know a bit about this (I realize the book is not about gaming, but hopefully you get what I mean).

Thanks!
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 49

Satya is the OpenGL guy on our team, so I'm afraid I can't help on this one.

- dave


Dave MacLean our book (Pro Android 4)
Augusto Sellhorn
Ranch Hand

Joined: May 24, 2007
Posts: 57
Let me ask it another way, do you know if there's a way to draw a UI control in a view's onDraw method? Say in my 2D game scene I want to draw and animate buttons in the middle of the scene? Or is this done with some type of overlay mechanism?

Thanks
Satya Komatineni
author
Ranch Hand

Joined: May 11, 2011
Posts: 38
Augusto,

I see the dilemma. I don't know the answer.

All I know is OpenGL drawing occurs on a special view called GLSurfaceView which itself is derived from a View. Here is what the doc says about this view

Manages a surface, which is a special piece of memory that can be composited into the Android view system
Provides a dedicated drawing surface embedded inside of a view hierarchy. You can control the format of this surface and, if you like, its size; the SurfaceView takes care of placing the surface at the correct location on the screen

The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed. The view hierarchy will take care of correctly compositing with the Surface any siblings of the SurfaceView that would normally appear on top of it. This can be used to place overlays such as buttons on top of the Surface, though note however that it can have an impact on performance since a full alpha-blended composite will be performed each time the Surface changes.


It may be obliquely pointing to what you are refering to.


My Web Site: satyakomatineni.com
Our Book for Tablets/Phones: Pro Android 3
Augusto Sellhorn
Ranch Hand

Joined: May 24, 2007
Posts: 57
Actually that's good info. It sounds like for GL views they have something similar to Swing's layered panes. Will have to try it out.

For a 2D view, what I'm thinking is maybe I can pass the Canvas object to the onDraw method of a GUI control. I'm just getting started on Android so sorry, haven't tried out a bunch of these things, just trying to move from the Swing world :-)
Satya Komatineni
author
Ranch Hand

Joined: May 11, 2011
Posts: 38
I think you will find Android a good company then.

I am quite jealous of the EXTENSIVE graphics API in Android. Probably the most extensive of the Android APIs. You can see this from the sample programs that come with the android sdk.

However having spoiled by the web for so many years I haven't had a chance to cover the graphics API much as I will need to refresh the basic drawing principles on a canvas and using the drawable views etc. Not sure at all when I will get a chance to do that at this moment.

This is one area that needs a good short book

Satya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mixing Android GUI controls with game graphics