Problem with handling input on android, namely in hello-gl2.

Problems with Canvas, OpenGL, etc...

Problem with handling input on android, namely in hello-gl2.

Postby Mockarutan » Sun Mar 13, 2011 12:49 am

How to i make the input handling run in a separate thread? I have modified the hello-gl2 example like this:


Code: Select all
package com.android.gl2jni;
   
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.WindowManager;
   
    import java.io.File;
   
   
    public class GL2JNIActivity extends Activity {
   
        GL2JNIView mView;
   
        @Override protected void onCreate(Bundle icicle) {
            super.onCreate(icicle);
           
            mView = new GL2JNIView(getApplication());
            setContentView(mView);
            setRequestedOrientation(0);
        }
   
        @Override protected void onPause() {
            super.onPause();
            mView.onPause();
        }
   
        @Override protected void onResume() {
            super.onResume();
            mView.onResume();
        }
   
        //the modified part
       @Override
       public boolean onTouchEvent(MotionEvent event) {
          // TODO Auto-generated method stub
          //return super.onTouchEvent(event);
          mView.queueEvent(new Runnable() {
               public void run() {
                  try {
                   Thread.sleep(33);
                } catch (InterruptedException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
                }
               }
           });
           return true;
       }
       
    }


This i to try to make the system lag less when i touch the screen continuously, I have seen this solution being used in other openGL apps on the android, although not with openGl ES 2.0. The problem is that my rendering freezes when call thread.sleep. But isn't it suppose to be in a separate thread that not effect the rendering thread?
Mockarutan
Freshman
Freshman
 
Posts: 3
Joined: Thu Jan 06, 2011 3:29 pm

Top

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

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest