Android Controls on GLSurfaceView

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

Android Controls on GLSurfaceView

Postby Hachaso » Thu Mar 04, 2010 11:01 pm

Hi!

Is it possible to draw Android Controls on top of GLSurfaceView?

any examples?
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Top

Re: Android Controls on GLSurfaceView

Postby pskink » Thu Mar 04, 2010 11:06 pm

Hachaso wrote:Hi!

Is it possible to draw Android Controls on top of GLSurfaceView?

any examples?


<FrameLayout>
<your gl surface view>
<LinearLayout>
your controls go here
</LinearLayout>
</FrameLayout>
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Postby Hachaso » Fri Mar 05, 2010 9:52 am

Do you mean that I should to this with XML?

How is this done with JAVA coding?
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Postby pmws » Fri Mar 05, 2010 10:34 am

Hachaso wrote:Do you mean that I should to this with XML?

How is this done with JAVA coding?


Check out the SurfaceView Overlay Activity from the API Demos. That should put you on track.
http://developer.android.com/resources/ ... index.html


Paul
pmws
Developer
Developer
 
Posts: 37
Joined: Thu Sep 24, 2009 12:23 pm

Postby Hachaso » Fri Mar 05, 2010 11:03 am

Thanks a lot.
Just had a look at the API demo.

Well the thing there is that you have the OpenGL view inside the Android view somehow.

What if I want to have an OpenGL View.. have my 3D object, but add an Android Control to it. Is this possible?
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Postby mb_zi » Sat Mar 06, 2010 12:07 am

i know that when i started doing the 3d work on my game i was having control problems. onTouchEvent and onKeyUp override the touch and key events in the activity. thus if you don't have them in your glSurfaceView you wont have problems with using the keys and touch events in your activity. but if you do say have onTouchEvent your touch events will go to your surfaceview and not your activity etc. for me i just took out onKeyEvent as i don't need it for my game thus allows me to have the activity menu system for my game. but that really doesnt solve your question.. :-/ im not entirely sure on how to allow activity touch/key events and surfaceView key/touch events to coexist.

ill try something tonight and if i find out ill get right back :P
mb_zi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Feb 27, 2010 2:16 am

Top

Postby Hachaso » Sat Mar 06, 2010 12:18 am

Thanks a lot for all the answers. This place really is helpful.

What I would like to do is to add an Android button, or Android Text on top of the GLSurfaceView.
Combining OpenGL with native Android Controls.
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Postby mb_zi » Sat Mar 06, 2010 12:30 am

it might not be what you're after... but you could make a button in in open gl via a textured quad. all you need to do is check if the user presses in a certain x and y bounded area aka on the textured quad and if so change textures briefly (whilst the person is pressing in the right area) and do what you want it to achieve in the surface view.

e.g. if your button textured quad fills the bottom 8% of the screen from left to right. using below would check if the user presses within the button area.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onTouchEvent(MotionEvent event)
  2.  
  3.         {
  4.  
  5.                 //Gets current x and y coordinates
  6.  
  7.                 float x = event.getX();
  8.  
  9.                 float y = event.getY();
  10.  
  11.  
  12.  
  13.                 //If someone touches the screen and moves
  14.  
  15.                 if(event.getAction() == MotionEvent.ACTION_MOVE)
  16.  
  17.                 {
  18.  
  19.                         int upperArea = this.getHeight() / 8;
  20.  
  21.                         int lowerArea = this.getHeight() - upperArea;
  22.  
  23.                         if(y > lowerArea)
  24.  
  25.                         {              
  26.  
  27.                                 //BUTTON STUFF HERE
  28.  
  29.                         }
  30.  
  31.                 }
  32.  
  33.                 return true;
  34.  
  35.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
mb_zi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Feb 27, 2010 2:16 am

Re:

Postby gemch » Mon Dec 13, 2010 1:19 pm

mb_zi wrote:it might not be what you're after... but you could make a button in in open gl via a textured quad. all you need to do is check if the user presses in a certain x and y bounded area aka on the textured quad and if so change textures briefly (whilst the person is pressing in the right area) and do what you want it to achieve in the surface view.

e.g. if your button textured quad fills the bottom 8% of the screen from left to right. using below would check if the user presses within the button area.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onTouchEvent(MotionEvent event)
  2.         {
  3.                 //Gets current x and y coordinates
  4.                 float x = event.getX();
  5.                 float y = event.getY();
  6.  
  7.                 //If someone touches the screen and moves
  8.                 if(event.getAction() == MotionEvent.ACTION_MOVE)
  9.                 {
  10.                         int upperArea = this.getHeight() / 8;
  11.                         int lowerArea = this.getHeight() - upperArea;
  12.                         if(y > lowerArea)
  13.                         {              
  14.                                 //BUTTON STUFF HERE
  15.                         }
  16.                 }
  17.                 return true;
  18.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


what if i want to start a new activity in that button stuff control?
as if in GL surfaceview?
now my implement have A class extends activity, B class extends gl surfaceview,
and one getResult() in class B,
in class use getResult() from B, but in class A is extends activity, so i wite getResult() in class A's onCreate(),
in activity life cycle it just run once when it create,
so my problem is i can't get the current change in class B to go into another activity.
i appreciate for replying
gemch
Freshman
Freshman
 
Posts: 3
Joined: Thu Dec 09, 2010 3:14 pm

Top

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

Who is online

Users browsing this forum: No registered users and 5 guests