GLSurfaceView onTouchEvent not working at all. #21383
-
I have a simple Android application with OpenGL (GLES Version 2) that draws a simple colored square and works without a problem so far. I have the GlSurfaceView set as my own custom View and the Renderer where the square is drawn. I am confused with the onTouchEvent. I want to change the square’s color to a random one every time I touch the screen. The process of setting up random values within a range for the square’s color array is easy to do, but getting the touch listener to work appears not. So far, I’ve been only getting results online with outdated GLES versions or the solutions I’m looking for, but they don’t seem to work for me at all. First thing I tried to do is overriding the onTouchEvent in my GLSurfaceView class where my custom function in the Renderer gets called to change the square’s color when there’s a touch event, in this case when I simply tap on my screen. Calling the @OverRide onTouchEvent in GLSurfaceView didn’t do anything. Then I tried setting the touch listener for the GLSurfaceView view in the Main Activity. Still nothing. It seems to be only not working for me for some reason. Here’s what I did. (Currently you’re seeing setting the listener for the GLSurfaceView view in the MainActivity): activity_main.xml <FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android” MainActivity.java public class MainActivity extends AppCompatActivity { OpenGLView.java (This is my GLSurfaceView class) public class OpenGLView extends GLSurfaceView OpenGLRenderer.java (My renderer class) public class OpenGLRenderer implements GLSurfaceView.Renderer I sure hope I haven’t missed something. I only gave you the necessary information. Everything GLES related is working except the onTouchEvent. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You might check to see if there is a problem with touch mode. Try calling
in the view to confirm that touch is enabled. It’s possible (see this) your onTouch override in the activity needs to read as so:
Would a click listener do the trick? Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped! |
Beta Was this translation helpful? Give feedback.
-
Hello, sorry for the late reply. I have solved my problem. The renderer class should implement the GLSurfaceView class that I have made instead.
|
Beta Was this translation helpful? Give feedback.
Hello, sorry for the late reply. I have solved my problem.
The renderer class should implement the GLSurfaceView class that I have made instead.