Beispiel #1
1
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    glSurfaceView = new GLSurfaceView(this);

    // Check if the system supports OpenGL ES 2.0.
    final ActivityManager activityManager =
        (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
    final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

    final MyRenderer mRenderer = new MyRenderer(this);

    if (supportsEs2) {
      // Request an OpenGL ES 2.0 compatible context.
      glSurfaceView.setEGLContextClientVersion(2);

      // Set the renderer to our demo renderer, defined below.
      glSurfaceView.setRenderer(mRenderer);
      // save the context when onPause is called
      glSurfaceView.setPreserveEGLContextOnPause(true);
      rendererSet = true;
    } else {
      Toast.makeText(this, "This device does not support OpenGL ES 2.0.", Toast.LENGTH_LONG).show();
      return;
    }

    glSurfaceView.setOnTouchListener(
        new View.OnTouchListener() {
          float previousX, previousY;

          @Override
          public boolean onTouch(View v, MotionEvent event) {

            // Dump touch event to log for debug
            // dumpEvent(event);

            // Handle touch events here...
            if (event != null) {
              switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:
                  previousX = event.getX();
                  previousY = event.getY();
                  Log.d(TAG, "mode=DRAG");
                  mode = DRAG;
                  break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_POINTER_UP:
                  Log.d(TAG, "mode=NONE");
                  mode = NONE;
                  break;
                case MotionEvent.ACTION_POINTER_DOWN:
                  oldDist = spacing(event);
                  Log.d(TAG, "oldDist=" + oldDist);
                  if (oldDist > 10f) {
                    midPoint(mid, event);
                    mode = ZOOM;
                    Log.d(TAG, "mode=ZOOM");
                  }
                  break;
                case MotionEvent.ACTION_MOVE:
                  if (mode == DRAG) {
                    final float deltaX = event.getX() - previousX;
                    final float deltaY = event.getY() - previousY;

                    previousX = event.getX();
                    previousY = event.getY();

                    glSurfaceView.queueEvent(
                        new Runnable() {
                          @Override
                          public void run() {
                            mRenderer.handleTouchDrag(deltaX, deltaY);
                          }
                        });
                  } else if (mode == ZOOM) {
                    float newDist = spacing(event);
                    Log.d(TAG, "newDist=" + newDist);
                    if (newDist > 10f) {
                      final float scale = newDist / oldDist;
                      Log.d(TAG, "scale=" + scale);

                      glSurfaceView.queueEvent(
                          new Runnable() {
                            @Override
                            public void run() {
                              mRenderer.handlePinchZoom(scale);
                            }
                          });
                    }
                  }
                  break;
              }
              return true;
            } else {
              return false;
            }
          }
        });
    setContentView(glSurfaceView);
    getActionBar().setTitle("Awesome Face");
    getActionBar().setDisplayHomeAsUpEnabled(true);
  }
Beispiel #2
0
  /**
   * initializing viewport set window properties (width, height, fullscreen, orientation based on
   * config) initialize touch listener if config.sensor initialize sound if config.sound initialize
   * music if config.music
   *
   * @param state
   */
  public void create(Bundle state) {
    super.onCreate(state);
    restore(getIntent().getExtras());
    if (config.fullscreen) {
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    if (config.orientation == Config.LANDSCAPE) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    view = new GLSurfaceView(this);
    view.setRenderer(this);
    setContentView(view);
    view.setOnTouchListener(this);
    this.resources = getResources();
    this.screen = new Size(config.width, config.height);
    // this.strech = config.strech;

    if (config.sound) {
      sound = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
      // volume = (AudioManager) getSystemService (AUDIO_SERVICE);
    }
    if (config.sensor) {
      sensor = (SensorManager) getSystemService(SENSOR_SERVICE);
      accelerometer = sensor.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    }
  }
 private void initGLSurfaceView() {
   if (glView != null) {
     glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
     glView.setRenderer(renderer);
     glView.setOnTouchListener(this);
   }
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mGLView = new GiderosGLSurfaceView(this);
    setContentView(mGLView);
    mGLView.setOnTouchListener(this);

    WeakActivityHolder.set(this);

    GiderosApplication.onCreate(externalClasses);
  }
Beispiel #5
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setBackgroundDrawable(null);
    created = true;
    Log.d(TAG, "onCreate");

    pipe = new DataPipe(this);
    cam = new Camera();
    engine = new Engine(pipe, cam);

    gameView = new GLSurfaceView(this);
    gameView.setEGLContextClientVersion(2);

    gameView.setOnTouchListener(this);
  }
 private void initGLSurfaceView() {
   if (glView != null) {
     glView.setRenderer(renderer);
     glView.setOnTouchListener(this);
   }
 }