Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3424346
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:27:48+00:00 2026-05-18T06:27:48+00:00

Manual is pretty vague even for regular views, and doesn’t even mention mGLSurfaceView in

  • 0

Manual is pretty vague even for regular views, and doesn’t even mention mGLSurfaceView in the UI events overview page.

For starters, all the examples will not work because they rely on the Id for the view (e.g. Button button = (Button)findViewById(R.id.corky);). I’m having a bad time trying to send UI events back and forth. I used the shotgun solution and attached every input event from the mGLSurfaceView to the Activity… But i’m craving for something better.

So, anyone brave enough to conjure a simple example with an Activity, a mGLSurfaceView, and the activity onTouch event saying where was the click relative to the size of the screen? (e.g. w=50%, h=50% for a perfect click on the center of the screen)


public class GlClick extends Activity implements OnTouchListener {
    @Override
    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        mGLSurfaceView.setRenderer(new GlRenderer());
        setContentView(mGLSurfaceView);
        mGLSurfaceView.setOnTouchListener(this);
    }
    public boolean onTouch(View v, MotionEvent event) {
        Log.d(TAG, "example output: click was on 234x211 for a 800x600 screen.")
    }
}

class GlRenderer implements Renderer {
    // here be lots of messy beginner GL code ...
    // ... you'd have wished for dragons.
    public void onSurfaceChanged(GL10 gl, int w, int h) {
        screenWidth = w;
        screenHeight = h;
        //TODO: send that to the activity
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:27:49+00:00Added an answer on May 18, 2026 at 6:27 am

    I’m working on a app ogl on android

    I don’t use any touch listener or anything pre made because sooner or later you lose time trying to figure out how to do something lol

    what I found to work well is simply

    @Override
        public boolean onTouchEvent(MotionEvent event) {
            if(sr != null){
                /*if(event.getAction() == MotionEvent.ACTION_DOWN){
                }else if(event.getAction() == MotionEvent.ACTION_MOVE){
                }else if(event.getAction() == MotionEvent.ACTION_CANCEL){
                }else if(event.getAction() == MotionEvent.ACTION_UP){*/
                GameHandler.onTouchEvent(event);
                //}
            }
            return true;
        }
    

    and in the GameHandler I first convert the touch from the screen coordinates to the glworld coordinates.

    in my ui elements I have the position and the size and I add a method “touch(…)” or “isTouched()”

    by my experiences this works quite well and I recommend you to try it ^^

    edit touch convertion

    public static void convertTouchToWorldRef(Vect vect){
            vect.y = (SceneRenderer.Height-vect.y)/SceneRenderer.Height*SceneRenderer.GAME_DIMENSION_H;
            vect.x = (vect.x)/SceneRenderer.Width*SceneRenderer.GAME_DIMENSION_W;
        }
    ;
    

    you need on the y to do height-y (ogl and android have different location of the origin)

    GAME_DIMENSION_* is the size of the ogl world projection plane (800*600).

    then its basic maths (I can’t remember the english name) but its thales formula x1/X1 = x2/X2.

    Edit: Vector

    public class Vector{
    private float x = 0;
    private float y = 0;
    public Vector(float x, float y){
        this.x = x;
        this.y = y;
    }
    //add accessors get/set
    ...
    }
    

    You can browse internet for better examples such as http://www.gamedev.net/community/forums/topic.asp?topic_id=302771

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new at this. Tried to make sense of the manual page for
When writing manual SQL its pretty easy to estimate the size and shape of
The manual page for XML::Parser::Style::Objects is horrible. A simple hello world style program would
I generally use a manual process: Look at the page, figure out the semantic
The scribd fullscreen mode is pretty neat (example: http://www.scribd.com/doc/13161906/Java-Lab-Manual-With-Java-Installation-Guide?classic_ui=1 ). The advantage (for RIAs
I have a pretty simple scenario using manual data operations with rad list view.
I'm pretty new to Akka and couldn't find the answer in the reference manual.
I currently use pretty exclusively the PHP stream context functionality (see https://www.php.net/manual/en/function.stream-context-create.php ) to
I have a pretty simple image switcher, which I use for manual images switcher
I found a reference in the PHP manual, but my interpretation is pretty much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.