Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a simple OpenGL app that draws a circle, I want to move the circle based on where a person touches the screen. The problem is, OpenGL sees the height and width as -1 to 1, whereas Android sees it based on pixel (I.E. 725). I convert it using the following...

public boolean onTouch(View view, MotionEvent event) {
  float moveX = ((event.getX())-(size.x/2))/(size.x/2);
  Log.d("Debug", "Y "+ event.getY());
  Log.d("Debug", "Height "+ size.y);
  float moveY = ((size.y/2)-(event.getY()))/(size.y/2);
  Log.d("Debug", "MoveY "+ moveY);
  return true;

Problem is it doesn't quite line up in the emulator, for example if I click near the bottom the circle looks like follows...

OpenGL Example

The console output looks as follows....

05-25 13:58:48.859: D/Debug(14185): Y 776.0
05-25 13:58:48.859: D/Debug(14185): Height 856
05-25 13:58:48.859: D/Debug(14185): MoveY -0.8130841

Anyone know how I can improve this so the middle of the circle lines up more closely to where I select? Why does the screen seem to return a higher value than what is displayed in the emulator?


I changed it to match the Android way (changing the ortho matrix) but that doesn't help I get the same response.

share|improve this question
You can setup your OpenGL coordinate system however you like. Just set it to the same coordinate system like Android via glOrtho. glOrtho(0, sizeofSurface.x, sizeofSurface.y, 0, 2.0, -2.0); –  Mr. Beast May 25 '13 at 14:10
So the -2s are depth (I.E. z value?) –  Jackie May 25 '13 at 14:12
Also fyi in OpenGL ES 1.1 this function is called GL_API void GL_APIENTRY glOrthof (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); And actually I can't find it at all in GLES 2.0 –  Jackie May 25 '13 at 14:19
Ah right, you'll need to compose the matrix yourself on ES 2 and apply it in a shader. –  Mr. Beast May 25 '13 at 14:25
Yeah I am thinking this is similar only in C++ (I don't want to use c++)... stackoverflow.com/questions/7131037/… I am going to play around but if you come up with an example first I will give you the check. Thanks for pushing me in the right direction either way. –  Jackie May 25 '13 at 14:28
show 2 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.