Ejemplo n.º 1
0
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    GLES20.glClearColor(0.0f, 0.0f, 0f, 1.0f);
    // GLES20.glShadeModel(GL11.GL_SMOOTH);
    GLES20.glClearDepthf(1.0f);
    GLES20.glDisable(GL11.GL_DEPTH_TEST);
    // gl.glDepthFunc(GL11.GL_LEQUAL);
    // GLES20.glHint(GLES20.GL_PERSPECTIVE_CORRECTION_HINT,
    //        GLES20.GL_NICEST);

    GLES20.glDisable(GL11.GL_CULL_FACE);

    // ByteBuffer temp = ByteBuffer.allocateDirect(16);
    // temp.order(ByteOrder.nativeOrder());
    /*
    gl.glLightfv(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer) temp
                    .asFloatBuffer().put(lightAmbient).flip()); // Setup The Ambient
                                                                                                            // Light
    gl.glLightfv(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer) temp
                    .asFloatBuffer().put(lightDiffuse).flip()); // Setup The Diffuse
                                                                                                            // Light
    gl.glLightfv(GL11.GL_LIGHT1, GL11.GL_POSITION, (FloatBuffer) temp
                    .asFloatBuffer().put(lightPosition).flip()); // Position The
                                                                                                                    // Light
    gl.glEnable(GL11.GL_LIGHT1); // Enable Light One
    */

    // Display.setVSyncEnabled(true);

    Log.d("openglrenderer", "createSurface : initialized = " + initialized);
    if (!initialized) { // Doesn't work at each attempt

      client.getEngineZildo().initializeClient(false);
      client.setMenuListener(new AndroidMenuListener(touchListener));
      touchListener.init();
      // Holes
      client.setOpenGLGestion(Zildo.pdPlugin.openGLGestion);
      Zildo.pdPlugin.openGLGestion.setClientEngineZildo(client.getEngineZildo());

      // gl.glClearColor(0.0f, 0.0f, 0f, 0.0f);

      Log.d("renderer", "init finished - start main menu");

      // unused.glDisable(GL11.GL_LIGHTING);

      initialized = true;
    } else {
      // Recreate context by reloading all textures and shaders
      Log.d("openglrenderer", "recreating context");
      SpriteDisplay spriteDisplay = ClientEngineZildo.spriteDisplay;
      TileEngine tileEngine = ClientEngineZildo.tileEngine;
      tileEngine.loadTextures();
      Zildo.pdPlugin.initFilters(true);
      ClientEngineZildo.spriteEngine.init(spriteDisplay);
      AndroidPixelShaders.shaders.load();
    }
  }
Ejemplo n.º 2
0
  @Override
  public void onDrawFrame(GL10 gl) {
    if (initialized) {
      // Clears the screen and depth buffer.
      GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); // | // OpenGL docs.
      // GLES20.GL_DEPTH_BUFFER_BIT);

      GLES20.glViewport(0, 0, Zildo.viewPortX, Zildo.viewPortY);

      i++;
      long t1 = 0, t2;

      if (i % 50 == 0) {
        t1 = ZUtils.getTime();
      }
      client.mainLoop();

      if (i % 50 == 0) {
        t2 = ZUtils.getTime();
        Log.d("time", "OpenGL ES 2 : Elapsed " + (t2 - t1) + "ms");
      }
    }
  }