public void onSurfaceCreated(GL10 unused, EGLConfig config) {

    // Set the background frame color
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glDisable(GLES20.GL_DITHER);
    GLES20.glDisable(GL10.GL_LIGHTING);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    GLES20.glEnable(GL10.GL_BLEND);
    GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    inirBuffers();

    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
    GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram); // creates OpenGL program executables

    // get handle to the vertex shader's vPosition member

    maPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
    maTexCoordsHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoords");
    mSampleHandle = GLES20.glGetUniformLocation(mProgram, "u_Texture");
    //        mSampleHandle2 = GLES20.glGetUniformLocation(mProgram, "u_Texture2");
    mOpacityHandle = GLES20.glGetUniformLocation(mProgram, "u_Opacity");
  }
  @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();
    }
  }
  @Override
  public void onDrawFrame(GL10 glUnused) {

    boolean barrelDistortionEnabled = mDisplayModeManager.isAntiDistortionEnabled();

    glCheck("MD360Renderer onDrawFrame 0");

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    glCheck("MD360Renderer onDrawFrame 1");
    int size = mDisplayModeManager.getVisibleSize();

    int width = (int) (this.mWidth * 1.0f / size);
    int height = mHeight;

    if (barrelDistortionEnabled) {
      // Barrel Distortion take over
      mBarrelDistortionPlugin.takeOver(mWidth, mHeight, size);
    }

    for (int i = 0; i < size; i++) {
      MD360Director director = mProjectionModeManager.getDirectors().get(i);
      GLES20.glViewport(width * i, 0, width, height);
      GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
      GLES20.glScissor(width * i, 0, width, height);

      Iterator<MDAbsPlugin> iterator = mPluginManager.getPlugins().iterator();
      while (iterator.hasNext()) {
        MDAbsPlugin plugin = iterator.next();
        plugin.setup(mContext);
        plugin.renderer(i, width, height, director);
      }

      GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    }

    if (barrelDistortionEnabled) {
      // Barrel Distortion render
      for (int i = 0; i < size; i++) {

        GLES20.glViewport(width * i, 0, width, mHeight);
        GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
        GLES20.glScissor(width * i, 0, width, mHeight);
        mBarrelDistortionPlugin.commit(i);
        GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
      }
    }

    // mFps.step();
  }
 /** Draws a red box in the corner. */
 private void drawBox() {
   GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
   GLES20.glScissor(0, 0, 100, 100);
   GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
   GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
   GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
 }
  @Override
  public void onDrawFrame(GL10 unused) {

    GLES20.glClearColor(0f, 0f, 0f, 0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (mShaderCompilerSupport[0] == false) {
      return;
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    float angle = (SystemClock.uptimeMillis() % 5000) / 5000f * 360;
    Matrix.setRotateM(mMatrixModel, 0, angle, 1, 2, 0);

    Matrix.multiplyMM(mMatrixModelViewProjection, 0, mMatrixView, 0, mMatrixModel, 0);
    Matrix.multiplyMM(
        mMatrixModelViewProjection, 0, mMatrixProjection, 0, mMatrixModelViewProjection, 0);

    mShaderSpline.useProgram();

    GLES20.glUniformMatrix4fv(
        mShaderSpline.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0);

    GLES20.glVertexAttribPointer(
        mShaderSpline.getHandle("aPosition"), 2, GLES20.GL_FLOAT, false, 0, mBufferSpline);
    GLES20.glEnableVertexAttribArray(mShaderSpline.getHandle("aPosition"));

    for (float[] ctrl : mSplines) {
      GLES20.glUniform3fv(mShaderSpline.getHandle("uCtrl"), 4, ctrl, 0);
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, COUNT_VERTICES);
    }
  }
 public void drawObject(float[] paramArrayOfFloat)
   throws OpenGLException
 {
   if (!this.mInitialized);
   do
   {
     return;
     if (this.mTextures.size() == 0)
     {
       LG.d("No textures defined!");
       return;
     }
     this.mBackgroundSprite.setShader(this.mLineShader);
     this.mBackgroundSprite.setTexture((GLTexture)this.mTextures.get(0));
     this.mBackgroundSprite.draw(paramArrayOfFloat);
     this.mPreviewSprite.setTexture((GLTexture)this.mTextures.get(0));
     this.mPreviewSprite.setShader(this.mShader);
     this.mPreviewSprite.draw(paramArrayOfFloat);
   }
   while (!this.mValidEstimate);
   GLES20.glDisable(2929);
   updateCurrentFrameOutline();
   this.mLineShader.bind();
   this.mLineShader.setVertices(this.mOutlineVertices);
   this.mLineShader.setTransform(paramArrayOfFloat);
   this.mOutlineIndices.position(0);
   this.mOutlineVertices.position(0);
   GLES20.glLineWidth(2.0F);
   GLES20.glDrawElements(2, 20, 5123, this.mOutlineIndices);
   GLES20.glEnable(2929);
 }
Esempio n. 7
0
 /**
  * Applies the Rajawali default GL state to the driver. Developers who wish to change this default
  * behavior can override this method.
  */
 public void resetGLState() {
   GLES20.glEnable(GLES20.GL_CULL_FACE);
   GLES20.glCullFace(GLES20.GL_BACK);
   GLES20.glFrontFace(GLES20.GL_CCW);
   GLES20.glDisable(GLES20.GL_BLEND);
   GLES20.glEnable(GLES20.GL_DEPTH_TEST);
 }
  @Override
  public void draw(GL10 glUnused) {
    super.draw(glUnused);
    GLES20.glDisable(GLES20.GL_CULL_FACE);
    calcMVP();
    GLES20.glUniformMatrix4fv(getUniform(ShaderVal.MVP_MATRIX), 1, false, MVP, 0);
    GLES20.glEnableVertexAttribArray(ShaderVal.POSITION.loc);
    GLES20.glVertexAttribPointer(ShaderVal.POSITION.loc, 3, GLES20.GL_FLOAT, false, 0, vertices);

    if (useVertexColors) {
      GLES20.glEnableVertexAttribArray(ShaderVal.ATTRIB_COLOR.loc);
      GLES20.glVertexAttribPointer(
          ShaderVal.ATTRIB_COLOR.loc, 4, GLES20.GL_FLOAT, false, 0, colors);
    } else {
      GLES20.glUniform4f(
          getUniform(ShaderVal.UNIFORM_COLOR),
          color.getRed(),
          color.getGreen(),
          color.getBlue(),
          color.getAlpha());
    }

    GLES20.glDrawArrays(drawMode, 0, vertexCount);
    GLES20.glEnable(GLES20.GL_CULL_FACE);
  }
  @Override
  public void onDrawFrame(GL10 unused) {
    GLES20.glClearColor(0f, 0f, 0f, 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    if (mShaderCompilerSupport[0] == false) {
      return;
    }

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    long time = SystemClock.uptimeMillis();

    if (mLastRenderTime == -1) {
      for (Star star : mStarArray) {
        star.randomize();
        star.mPosition[2] = (float) (Math.random() * 4 - 2);
      }
      mLastRenderTime = time;
    }

    float t = (time - mLastRenderTime) / 1000f;
    mLastRenderTime = time;

    mShaderStar.useProgram();

    GLES20.glUniformMatrix4fv(
        mShaderStar.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0);
    GLES20.glUniform1f(mShaderStar.getHandle("uSize"), .01f);

    GLES20.glVertexAttribPointer(
        mShaderStar.getHandle("aPosition"), 2, GLES20.GL_BYTE, false, 0, mBufferVertices);
    GLES20.glEnableVertexAttribArray(mShaderStar.getHandle("aPosition"));

    for (Star star : mStarArray) {
      star.mPosition[2] += star.mSpeed * t;
      if (star.mPosition[2] > 2) {
        star.randomize();
      }
    }

    Arrays.sort(
        mStarArray,
        new Comparator<Star>() {
          @Override
          public int compare(Star arg0, Star arg1) {
            return arg0.mPosition[2] < arg1.mPosition[2] ? -1 : 1;
          }
        });

    for (Star star : mStarArray) {
      GLES20.glUniform3fv(mShaderStar.getHandle("uPosition"), 1, star.mPosition, 0);
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    }

    GLES20.glDisable(GLES20.GL_BLEND);
  }
Esempio n. 10
0
  protected void doColorPicking(ColorPickerInfo pickerInfo) {
    ObjectColorPicker picker = pickerInfo.getPicker();
    picker.getRenderTarget().bind();

    // Set background color (to Object3D.UNPICKABLE to prevent any conflicts)
    GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    // Configure depth testing
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthFunc(GLES20.GL_LESS);
    GLES20.glDepthMask(true);
    GLES20.glClearDepthf(1.0f);

    // Clear buffers used for color-picking
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Get the picking material
    Material pickingMaterial = picker.getMaterial();

    // Can't blend picking colors
    GLES20.glDisable(GLES20.GL_BLEND);

    // Render the Skybox first (no need for depth testing)
    if (mSkybox != null && mSkybox.isPickingEnabled()) {
      GLES20.glDisable(GLES20.GL_DEPTH_TEST);
      GLES20.glDepthMask(false);
      mSkybox.renderColorPicking(mCamera, pickingMaterial);
      GLES20.glEnable(GLES20.GL_DEPTH_TEST);
      GLES20.glDepthMask(true);
    }

    // Render all children using their picking colors
    synchronized (mChildren) {
      for (int i = 0, j = mChildren.size(); i < j; ++i) {
        mChildren.get(i).renderColorPicking(mCamera, pickingMaterial);
      }
    }

    // pickObject() unbinds the renderTarget's framebuffer...
    ObjectColorPicker.pickObject(pickerInfo);
  }
 public void undistortTexture(final int textureId) {
   if (this.mRestoreGLStateEnabled) {
     if (this.mChromaticAberrationCorrectionEnabled) {
       this.mGLStateBackupAberration.readFromGL();
     } else {
       this.mGLStateBackup.readFromGL();
     }
   }
   if (this.mFovsChanged || this.mTextureFormatChanged) {
     this.updateTextureAndDistortionMesh();
   }
   GLES20.glViewport(
       0, 0, this.mHmd.getScreenParams().getWidth(), this.mHmd.getScreenParams().getHeight());
   GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
   GLES20.glDisable(GLES20.GL_CULL_FACE);
   GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
   GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
   if (this.mChromaticAberrationCorrectionEnabled) {
     GLES20.glUseProgram(this.mProgramHolderAberration.program);
   } else {
     GLES20.glUseProgram(this.mProgramHolder.program);
   }
   GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
   GLES20.glScissor(
       0, 0, this.mHmd.getScreenParams().getWidth() / 2, this.mHmd.getScreenParams().getHeight());
   this.renderDistortionMesh(this.mLeftEyeDistortionMesh, textureId);
   GLES20.glScissor(
       this.mHmd.getScreenParams().getWidth() / 2,
       0,
       this.mHmd.getScreenParams().getWidth() / 2,
       this.mHmd.getScreenParams().getHeight());
   this.renderDistortionMesh(this.mRightEyeDistortionMesh, textureId);
   if (this.mRestoreGLStateEnabled) {
     if (this.mChromaticAberrationCorrectionEnabled) {
       this.mGLStateBackupAberration.writeToGL();
     } else {
       this.mGLStateBackup.writeToGL();
     }
   }
 }
  @Override
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    // Set rendering options
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    GLES20.glDisable(GLES20.GL_DITHER);

    // Face culling
    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glFrontFace(GL10.GL_CCW);
    GLES20.glCullFace(GLES20.GL_BACK);

    // Depth
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glDepthFunc(GLES20.GL_LEQUAL);
    GLES20.glDepthMask(true);
  }
Esempio n. 13
0
  private void renderLines() {
    if (phenixLineProgram != null) {
      if (!phenixLineProgram.use()) {
        return;
      }

      float angle =
          360.0f * getTimeDeltaByScale((long) (1 * 50000L / speedFactor / rotationSpeedFactor));
      Matrix.setRotateM(M_matrix, 0, angle, 0, 0, 1.0f);

      Matrix.multiplyMM(MVP_matrix, 0, V_matrix, 0, M_matrix, 0);
      Matrix.multiplyMM(MVP_matrix, 0, P_matrix, 0, MVP_matrix, 0);

      float delta = getTimeDeltaByScale((long) (1 * 25000L / speedFactor));

      lineVertices.bind(phenixLineProgram, "aPosition", null);

      GLES20.glUniformMatrix4fv(
          phenixLineProgram.getUniformLocation("uMVPMatrix"), 1, false, MVP_matrix, 0);

      GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), delta);
      GLES20.glUniform1f(
          phenixLineProgram.getUniformLocation("uBrightness"), brightness * brightnessFactor);
      GLES20.glUniform3f(
          phenixLineProgram.getUniformLocation("uColor"),
          linesColorRed,
          linesColorGreen,
          linesColorBlue);

      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);
      GLES20.glLineWidth(lineWidth * lineWidthFactor);

      lineVertices.draw(GLES20.GL_LINES, 0, MOVING_LINE_COUNT);

      GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), 0.0f);

      lineVertices.draw(GLES20.GL_LINES, MOVING_LINE_COUNT, STALE_LINE_COUNT);

      GLES20.glDisable(GLES20.GL_BLEND);

      lineVertices.unbind(phenixLineProgram, "aPosition", null);
    }
  }
Esempio n. 14
0
  public void Draw() {
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexture.getID());
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    // GLES20.glDisable(GLES20.GL_CULL_FACE);
    // GLES20.glDisable(GLES20.GL_LIGHTING);
    // GLES20.glPushMatrix();
    // GLES20.glTranslatef(position.X, position.Y, position.Z);
    Renderer.pushModelViewMatrix();
    Renderer.modelview.translate(position.X, position.Y, position.Z);
    // GLES20.glScalef(scale, scale, scale);
    Renderer.modelview.scale(scale, scale, scale);
    Renderer.loadModelViewMatrix();

    mVertexBuffer.Draw(mIndexBuffer);
    // GLES20.glPopMatrix();
    Renderer.popModelViewMatrix();
    Renderer.loadModelViewMatrix();
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    // GLES20.glEnable(GLES20.GL_CULL_FACE);
    // GLES20.glEnable(GLES20.GL_LIGHTING);
  }
  /**
   * Generates a frame of data using GL commands.
   *
   * <p>We have an 8-frame animation sequence that wraps around. It looks like this:
   *
   * <pre>
   *   0 1 2 3
   *   7 6 5 4
   * </pre>
   *
   * We draw one of the eight rectangles and leave the rest set to the zero-fill color.
   */
  private void generateSurfaceFrame(int frameIndex) {
    frameIndex %= 8;

    int startX, startY;
    if (frameIndex < 4) {
      // (0,0) is bottom-left in GL
      startX = frameIndex * (mWidth / 4);
      startY = mHeight / 2;
    } else {
      startX = (7 - frameIndex) * (mWidth / 4);
      startY = 0;
    }

    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
    GLES20.glClearColor(TEST_R0 / 255.0f, TEST_G0 / 255.0f, TEST_B0 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(startX, startY, mWidth / 4, mHeight / 2);
    GLES20.glClearColor(TEST_R1 / 255.0f, TEST_G1 / 255.0f, TEST_B1 / 255.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
  }
  private void drawParticles() {
    float currentTime = (System.nanoTime() - globalStartTime) / 1000000000f;

    redParticleShooter.addParticles(particleSystem, currentTime, 1);
    greenParticleShooter.addParticles(particleSystem, currentTime, 1);
    blueParticleShooter.addParticles(particleSystem, currentTime, 1);

    setIdentityM(modelMatrix, 0);
    updateMvpMatrix();

    glDepthMask(false);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);

    particleProgram.useProgram();
    particleProgram.setUniforms(modelViewProjectionMatrix, currentTime, particleTexture);
    particleSystem.bindData(particleProgram);
    particleSystem.draw();

    glDisable(GL_BLEND);
    glDepthMask(true);
  }
Esempio n. 17
0
  private void renderBlurTexture(int textureIndex) {
    if (postProgram.use()) {
      renderTextures[textureIndex].bind(GLES20.GL_TEXTURE0, postProgram, "sTexture");
      quadVertices.bind(postProgram, "aPosition", "aTextureCoord");

      GLES20.glUniform1f(postProgram.getUniformLocation("uBlur"), blur * blurFactor);

      GLES20.glUniformMatrix4fv(
          postProgram.getUniformLocation("uMVPMatrix"), 1, false, Q_matrix, 0);

      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);

      quadVertices.draw(GLES20.GL_TRIANGLE_STRIP);

      GLES20.glDisable(GLES20.GL_BLEND);

      quadVertices.unbind(postProgram, "aPosition", "aTextureCoord");

      renderTextures[textureIndex].unbind(GLES20.GL_TEXTURE0);
    }
  }
Esempio n. 18
0
  /** Draw the desktop. Make sure {@link hasVideoFrame} returns true. */
  public void draw(float[] combinedMatrix, boolean isTransparent) {
    GLES20.glUseProgram(mProgramHandle);

    // Pass in model view project matrix.
    GLES20.glUniformMatrix4fv(mCombinedMatrixHandle, 1, false, combinedMatrix, 0);

    // Pass in texture coordinate.
    GLES20.glVertexAttribPointer(
        mTextureCoordinateHandle,
        TEXTURE_COORDINATE_DATA_SIZE,
        GLES20.GL_FLOAT,
        false,
        0,
        TEXTURE_COORDINATES);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    GLES20.glVertexAttribPointer(
        mPositionHandle, POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mPosition);
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Enable transparency.
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    // Pass in transparency.
    GLES20.glVertexAttrib1f(mTransparentHandle, isTransparent ? 0.5f : 1.0f);

    // Link texture data with texture unit.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, VERTICES_NUMBER);

    GLES20.glDisable(GLES20.GL_BLEND);
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordinateHandle);
  }
Esempio n. 19
0
  /** Generates a frame of data using GL commands. */
  private void generateFrame(int frameIndex) {
    final int BOX_SIZE = 80;
    frameIndex %= 240;
    int xpos, ypos;

    int absIndex = Math.abs(frameIndex - 120);
    xpos = absIndex * WIDTH / 120;
    ypos = absIndex * HEIGHT / 120;

    float lumaf = absIndex / 120.0f;

    GLES20.glClearColor(lumaf, lumaf, lumaf, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
    GLES20.glScissor(BOX_SIZE / 2, ypos, BOX_SIZE, BOX_SIZE);
    GLES20.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glScissor(xpos, BOX_SIZE / 2, BOX_SIZE, BOX_SIZE);
    GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
  }
    @Override
    public void onDrawFrame(GL10 gl) {
      // 清除深度缓冲与颜色缓冲
      GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

      MatrixState.pushMatrix();
      MatrixState.translate(0, -2, 0);
      desert.drawSelf(desertId);
      MatrixState.popMatrix();

      // 开启混合
      GLES20.glEnable(GLES20.GL_BLEND);
      // 设置混合因子
      GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

      MatrixState.pushMatrix();
      MatrixState.translate(0, -2, 0);

      group.drawSelf();

      MatrixState.popMatrix();
      // 关闭混合
      GLES20.glDisable(GLES20.GL_BLEND);
    }
Esempio n. 21
0
 @Override
 public void disable(final int feature) {
   checkOpenGLThread();
   GLES20.glDisable(feature);
 }
Esempio n. 22
0
 @Override
 public void glDisable(int cap) {
   GLES20.glDisable(cap);
 }
Esempio n. 23
0
  public void DrawModel() {

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, m.textureHandle[0]);
    Mat4 rot;
    if (!haslanded) {
      Vec3 cross = VecMath.CrossProduct(MainActivity.phone_n, MainActivity.init_phone_n);
      phone_n = MainActivity.phone_n;
      init_phone_n = MainActivity.init_phone_n;

      Vec3 ny = new Vec3(0, 0, -1);
      Vec3 cross2 = VecMath.CrossProduct(init_phone_n, ny);
      float ang2 = (float) Math.asin(VecMath.Norm(cross2) / (VecMath.Norm(init_phone_n)));
      ;
      Mat4 rotmat2 = VecMath.ArbRotate(cross2, ang2);
      // Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang);
      Mat4 rotmat = VecMath.ArbRotate(VecMath.Normalize(cross), MainActivity.phone_ang);

      if (Math.abs(init_phone_n.z) > Math.abs(init_phone_n.y))
        rotmat =
            VecMath.ArbRotate(
                VecMath.MultVec3(VecMath.Rx(-(float) Math.PI / 2), VecMath.Normalize(cross)),
                MainActivity.phone_ang);

      Mat4 rotmatf = VecMath.Mult(rotmat, rotmat2);

      Ro = rotmat;
      // Ro = VecMath.ArbRotate( VecMath.MultVec3(VecMath.Rx(-(float) Math.PI/2),
      // VecMath.Normalize(cross)), MainActivity.phone_ang);
      rot = VecMath.Mult(T, Ro);
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(rot.m));
    } else {
      rot = T;
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(rot.m));
      // Ro = rot;
    }

    // GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(Ro.m));
    m.DrawModel();
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

    // draw debug spheres
    for (int i = 0; i < 3; i++) {
      float r = .3f;
      float coss = (float) (r * Math.cos(Math.PI / 6 + i * 2 * Math.PI / 3));
      float sinn = (float) (r * Math.sin(Math.PI / 6 + i * 2 * Math.PI / 3));
      Vec3 poss = new Vec3(coss, -.5f, sinn);
      Mat4 TT = VecMath.T(poss);

      Mat4 SS = VecMath.S(.2f, .2f, .2f);
      Mat4 tott = VecMath.Mult(T, VecMath.Mult(Ro, VecMath.Mult(TT, SS)));
      fin_pos[i] = VecMath.MultVec3(tott, poss); // fin position in absolute coords
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(tott.m));
      sphere[i].DrawModel();
    }

    if (isthrusting && fuel > .0f) {
      GLES20.glUniform1i(GLES20.glGetUniformLocation(Shader.program, "draw_exhaustf"), 1);
      Mat4 Tf = VecMath.Mult(rot, VecMath.T(0, -.8f, 0));
      GLES20.glUniformMatrix4fv(Shader.rothandle, 1, true, makefloatbuffer(Tf.m));
      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
      GLES20.glDepthMask(false);
      fire.DrawModel();
      GLES20.glDepthMask(true);
      GLES20.glDisable(GLES20.GL_BLEND);
      GLES20.glUniform1i(GLES20.glGetUniformLocation(Shader.program, "draw_exhaustf"), 0);
    }
  }
Esempio n. 24
0
  public void render(
      long ellapsedTime, double deltaTime, RenderTarget renderTarget, Material sceneMaterial) {
    // Scene color-picking requests are relative to the prior frame's render
    // state, so handle any pending request before applying this frame's updates...
    if (mPickerInfo != null) {
      doColorPicking(mPickerInfo);
      // One-shot, once per frame at most
      mPickerInfo = null;
    }

    performFrameTasks(); // Handle the task queue

    synchronized (mFrameTaskQueue) {
      if (mLightsDirty) {
        updateMaterialsWithLights();
        mLightsDirty = false;
      }
    }

    synchronized (mNextSkyboxLock) {
      // Check if we need to switch the skybox, and if so, do it.
      if (mNextSkybox != null) {
        mSkybox = mNextSkybox;
        mNextSkybox = null;
      }
    }
    synchronized (mNextCameraLock) {
      // Check if we need to switch the camera, and if so, do it.
      if (mNextCamera != null) {
        mCamera = mNextCamera;
        mCamera.setProjectionMatrix(mRenderer.getViewportWidth(), mRenderer.getViewportHeight());
        mNextCamera = null;
      }
    }

    int clearMask = mAlwaysClearColorBuffer ? GLES20.GL_COLOR_BUFFER_BIT : 0;

    if (renderTarget != null) {
      renderTarget.bind();
      GLES20.glClearColor(mRed, mGreen, mBlue, mAlpha);
    } else {
      //			GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
      GLES20.glClearColor(mRed, mGreen, mBlue, mAlpha);
    }

    if (mEnableDepthBuffer) {
      clearMask |= GLES20.GL_DEPTH_BUFFER_BIT;
      GLES20.glEnable(GLES20.GL_DEPTH_TEST);
      GLES20.glDepthFunc(GLES20.GL_LESS);
      GLES20.glDepthMask(true);
      GLES20.glClearDepthf(1.0f);
    }
    if (mAntiAliasingConfig.equals(ISurface.ANTI_ALIASING_CONFIG.COVERAGE)) {
      clearMask |= GL_COVERAGE_BUFFER_BIT_NV;
    }

    GLES20.glClear(clearMask);

    // Execute onPreFrame callbacks
    // We explicitly break out the steps here to help the compiler optimize
    final int preCount = mPreCallbacks.size();
    if (preCount > 0) {
      synchronized (mPreCallbacks) {
        for (int i = 0; i < preCount; ++i) {
          mPreCallbacks.get(i).onPreFrame(ellapsedTime, deltaTime);
        }
      }
    }

    // Update all registered animations
    synchronized (mAnimations) {
      for (int i = 0, j = mAnimations.size(); i < j; ++i) {
        Animation anim = mAnimations.get(i);
        if (anim.isPlaying()) anim.update(deltaTime);
      }
    }

    // We are beginning the render process so we need to update the camera matrix before fetching
    // its values
    mCamera.onRecalculateModelMatrix(null);

    // Get the view and projection matrices in advance
    mVMatrix = mCamera.getViewMatrix();
    mPMatrix = mCamera.getProjectionMatrix();
    // Pre-multiply View and Projection matrices once for speed
    mVPMatrix.setAll(mPMatrix).multiply(mVMatrix);
    mInvVPMatrix.setAll(mVPMatrix).inverse();
    mCamera.updateFrustum(mInvVPMatrix); // Update frustum plane

    // Update the model matrices of all the lights
    synchronized (mLights) {
      final int numLights = mLights.size();
      for (int i = 0; i < numLights; ++i) {
        mLights.get(i).onRecalculateModelMatrix(null);
      }
    }

    // Execute onPreDraw callbacks
    // We explicitly break out the steps here to help the compiler optimize
    final int preDrawCount = mPreDrawCallbacks.size();
    if (preDrawCount > 0) {
      synchronized (mPreDrawCallbacks) {
        for (int i = 0; i < preDrawCount; ++i) {
          mPreDrawCallbacks.get(i).onPreDraw(ellapsedTime, deltaTime);
        }
      }
    }

    if (mSkybox != null) {
      GLES20.glDisable(GLES20.GL_DEPTH_TEST);
      GLES20.glDepthMask(false);

      mSkybox.setPosition(mCamera.getX(), mCamera.getY(), mCamera.getZ());
      // Model matrix updates are deferred to the render method due to parent matrix needs
      // Render the skybox
      mSkybox.render(mCamera, mVPMatrix, mPMatrix, mVMatrix, null);

      if (mEnableDepthBuffer) {
        GLES20.glEnable(GLES20.GL_DEPTH_TEST);
        GLES20.glDepthMask(true);
      }
    }

    if (sceneMaterial != null) {
      sceneMaterial.useProgram();
      sceneMaterial.bindTextures();
    }

    synchronized (mChildren) {
      for (int i = 0, j = mChildren.size(); i < j; ++i) {
        // Model matrix updates are deferred to the render method due to parent matrix needs
        mChildren.get(i).render(mCamera, mVPMatrix, mPMatrix, mVMatrix, sceneMaterial);
      }
    }

    if (mDisplaySceneGraph) {
      mSceneGraph.displayGraph(mCamera, mVPMatrix, mPMatrix, mVMatrix);
    }

    if (sceneMaterial != null) {
      sceneMaterial.unbindTextures();
    }

    synchronized (mPlugins) {
      for (int i = 0, j = mPlugins.size(); i < j; i++) mPlugins.get(i).render();
    }

    if (renderTarget != null) {
      renderTarget.unbind();
    }

    // Execute onPostFrame callbacks
    // We explicitly break out the steps here to help the compiler optimize
    final int postCount = mPostCallbacks.size();
    if (postCount > 0) {
      synchronized (mPostCallbacks) {
        for (int i = 0; i < postCount; ++i) {
          mPostCallbacks.get(i).onPostFrame(ellapsedTime, deltaTime);
        }
      }
    }
  }
Esempio n. 25
0
 @Override
 public void onSurfaceCreated(final GL10 unused, final EGLConfig config) {
   GLES20.glClearColor(0, 0, 0, 1);
   GLES20.glDisable(GLES20.GL_DEPTH_TEST);
   mFilter.init();
 }
Esempio n. 26
0
  /**
   * drawing function also calculates color value
   *
   * @param mvpMatrix
   */
  public void draw(float[] mvpMatrix) {
    float dif =
        Math.abs(midx - midTx)
            + Math.abs(midy - midTy)
            + Math.abs(sizx - sizTx)
            + Math.abs(sizy - sizTy);
    // Log.d("ASCII","dif"+dif);
    if (dif > 0.01) {
      midx += (midTx - midx) / 10.0f;
      midy += (midTy - midy) / 10.0f;
      sizx += (sizTx - sizx) / 10.0f;
      sizy += (sizTy - sizy) / 10.0f;
    }

    // color[0]= recBlink;
    // color[1]=1.0f-recBlink/5;
    // color[2]=1.0f-recBlink/5;

    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // get handle to texture coordinate variable
    mTextureHandle = GLES20.glGetAttribLocation(mProgram, "TexCoordIn");
    // if (mTextureHandle == -1) Log.e("ASCII", "TexCoordIn not found");

    // get handle to shape's texture reference
    fsTexture = GLES20.glGetUniformLocation(mProgram, "Texture");
    // if (fsTexture == -1) Log.e("ASCII", "Texture not found");

    //
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    // XQGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    // MyGLRenderer.checkGlError("glUniformMatrix4fv");

    //
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    //
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    GLES20.glVertexAttribPointer(
        mTextureHandle, COORDS_PER_TEXTURE, GLES20.GL_FLOAT, false, textureStride, textureBuffer);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureRef);
    GLES20.glUniform1i(fsTexture, 3);

    // GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glEnableVertexAttribArray(mTextureHandle);

    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    // Draw the shape
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLE_STRIP, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    GLES20.glDisable(GLES20.GL_BLEND);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureHandle);
  }
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glDisable(GLES20.GL_DEPTH_TEST);
      GLES20.glDisable(GLES20.GL_DITHER);
      GLES20.glDisable(GLES20.GL_STENCIL_TEST);
      GLES20.glDisable(GL10.GL_DITHER);

      String extensions = GLES20.glGetString(GL10.GL_EXTENSIONS);
      Log.d(TAG, "OpenGL extensions=" + extensions);

      // Ignore the passed-in GL10 interface, and use the GLES20
      // class's static methods instead.
      mProgram = createProgram(VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE);
      if (mProgram == 0) {
        return;
      }
      maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
      checkGlError("glGetAttribLocation aPosition");
      if (maPositionHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aPosition");
      }
      maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
      checkGlError("glGetAttribLocation aTextureCoord");
      if (maTextureHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aTextureCoord");
      }

      muSamplerYHandle = GLES20.glGetUniformLocation(mProgram, "SamplerY");
      if (muSamplerYHandle == -1) {
        throw new RuntimeException("Could not get uniform location for SamplerY");
      }
      muSamplerUHandle = GLES20.glGetUniformLocation(mProgram, "SamplerU");
      if (muSamplerUHandle == -1) {
        throw new RuntimeException("Could not get uniform location for SamplerU");
      }
      muSamplerVHandle = GLES20.glGetUniformLocation(mProgram, "SamplerV");
      if (muSamplerVHandle == -1) {
        throw new RuntimeException("Could not get uniform location for SamplerV");
      }

      mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
      GLES20.glVertexAttribPointer(
          maPositionHandle,
          3,
          GLES20.GL_FLOAT,
          false,
          TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
          mTriangleVertices);
      checkGlError("glVertexAttribPointer maPosition");

      mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
      GLES20.glEnableVertexAttribArray(maPositionHandle);
      checkGlError("glEnableVertexAttribArray maPositionHandle");
      GLES20.glVertexAttribPointer(
          maTextureHandle,
          2,
          GLES20.GL_FLOAT,
          false,
          TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
          mTriangleVertices);
      checkGlError("glVertexAttribPointer maTextureHandle");
      GLES20.glEnableVertexAttribArray(maTextureHandle);
      checkGlError("glEnableVertexAttribArray maTextureHandle");

      GLES20.glGenTextures(1, mTextureY, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureY[0]);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

      GLES20.glGenTextures(1, mTextureU, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureU[0]);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

      GLES20.glGenTextures(1, mTextureV, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureV[0]);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

      mSurfaceCreated = true;
    }
Esempio n. 28
0
  @Override
  public void onDrawFrame(GL10 glUnused) {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    // Set our per-vertex lighting program.
    GLES20.glUseProgram(mPerVertexProgramHandle);

    // Set program handles for cube drawing.
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
    mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
    mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
    mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
    mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
    mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
    mTextureCoordinateHandle =
        GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_TexCoordinate");

    // Set the active texture unit to texture unit 0.
    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(0));
    drawPlane(this.mGroundVertices, this.mGroundColors, this.mGroundNormals, mGroundTextures);
    // bind the next texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(1));
    drawPlane(this.mOceanVertices, this.mOceanColors, this.mOceanNormals, mOceanTextures);
    // bind the next texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(3));
    drawCube();

    // Get changes in finger positions and add to total for moving and rotating
    totalDiffX += diffX;
    totalDiffY += diffY;
    angleX += dx;
    angleY += dy;
    // to prevent the user from looking more than straight up and less and straight down.
    if (Math.abs(angleY) > 1.5f) {
      angleY -= dy;
    }

    // move the model matrix by finger distance changes for pinch zoom movement.
    Matrix.translateM(mModelMatrix, 0, this.diffX, this.diffY, 0);

    // rotate camera based on finger movements
    this.mCamera.look.x = (float) Math.cos(angleX);
    this.mCamera.look.y = (float) Math.sin(angleX);
    this.mCamera.look.z = (float) Math.tan(angleY);
    updateLookAt();

    // reset variables so that movement stops after finger movement stops
    this.dx = 0;
    this.dy = 0;
    this.diffX = 0;
    this.diffY = 0;

    // update the lookAt coordinates
    updateLookAt();
    // redraw each object in the array.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(2));
    synchronized (this.objects) {
      for (Prim p : this.objects) {
        p.draw(
            this.mPositionHandle,
            this.mColorHandle,
            this.mNormalHandle,
            this.mTextureCoordinateHandle);
      }
    }
    GLES20.glDisable(GLES20.GL_TEXTURE_2D);
  }
  ///////////////////////////////////////////////////////////////////////////////////////
  // render
  ///////////////////////////////////////////////////////////////////////////////////////
  // Draw every sprite's primitives
  ///////////////////////////////////////////////////////////////////////////////////////
  // IN: true=render BACKground
  //	   false=render FOREground
  ///////////////////////////////////////////////////////////////////////////////////////
  @Override
  public void render(int floor, boolean backGround) {

    // Display every sprites
    GLES20.glEnable(GLES20.GL_BLEND);

    float[] color = new float[4]; // =textureEngine.graphicStuff.getFloat(GL11.GL_CURRENT_COLOR, 4);
    color[0] = 1f;
    color[1] = 1f;
    color[2] = 1f;
    color[3] = 1f;

    Vector3f ambient = ClientEngineZildo.ortho.getAmbientColor();
    if (ambient != null) {
      color[0] = ambient.x;
      color[1] = ambient.y;
      color[2] = ambient.z;
    }
    // Respect order from bankOrder
    boolean endSequence = false;
    int posBankOrder = 0;

    // Retrieve the sprite's order
    int[][][] bankOrder = ClientEngineZildo.spriteDisplay.getBankOrder();

    int phase = (backGround) ? 0 : 1;
    while (!endSequence) {
      int numBank = bankOrder[floor][phase][posBankOrder * 4];
      if (numBank == -1) {
        endSequence = true;
      } else {
        // Render the n sprites from this bank
        int nbQuads = bankOrder[floor][phase][posBankOrder * 4 + 1];
        int iCurrentFX = bankOrder[floor][phase][posBankOrder * 4 + 2];
        int alpha = bankOrder[floor][phase][posBankOrder * 4 + 3];
        EngineFX currentFX = EngineFX.values()[iCurrentFX];
        int texId = textureEngine.getNthTexture(numBank);
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);

        // Select the right pixel shader (if needed)

        if (pixelShaderSupported) {
          switch (currentFX) {
            case NO_EFFECT:
              shaders.setCurrentShader(GLShaders.textured);
              break;
            case PERSO_HURT:
              // A sprite has been hurt
              shaders.setCurrentShader(GLShaders.wounded);
              shaders.setWoundedColor(
                  new Vector4f(
                      (float) Math.random(), (float) Math.random(), (float) Math.random(), 1));
              /*
              ARBShaderObjects.glUseProgramObjectARB(ClientEngineZildo.pixelShaders.getPixelShader(1));
              ClientEngineZildo.pixelShaders.setParameter(1, "randomColor", );
              */
              break;
            case YELLOW_HALO:
              shaders.setCurrentShader(GLShaders.goldFilter);
              shaders.setGoldFactor((float) (0.6 + 0.4 * Math.cos(3 * gamma)));
              break;
            case STAR:
              shaders.setCurrentShader(GLShaders.star);
              shaders.setStarNoise(gamma, (float) Math.random());
              break;
            default:
              if (currentFX.needPixelShader()) {
                // This is a color replacement, so get the right ones
                Vector4f[] tabColors =
                    ClientEngineZildo.pixelShaders.getConstantsForSpecialEffect(currentFX);

                // And enable the 'color replacement' pixel shader
                shaders.setCurrentShader(GLShaders.switchColor);
                shaders.setSwitchColors(tabColors);
                /*
                ClientEngineZildo.pixelShaders.setParameter(0, "Color1", tabColors[2]);
                ClientEngineZildo.pixelShaders.setParameter(0, "Color2", tabColors[3]);
                ClientEngineZildo.pixelShaders.setParameter(0, "Color3", tabColors[0].scale(color[0]));
                ClientEngineZildo.pixelShaders.setParameter(0, "Color4", tabColors[1].scale(color[0]));
                */
              } else {
                shaders.setCurrentShader(GLShaders.textured);
              }
          }
        }

        switch (currentFX) {
          case SHINY:
            GLES20.glBlendFunc(GLES20.GL_SRC_COLOR, GLES20.GL_ONE); // _MINUS_SRC_ALPHA);
            shaders.setColor(1, (float) Math.random(), 0, (float) Math.random());
            break;
          case QUAD:
            GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
            shaders.setColor(
                0.5f + 0.5f * (float) Math.random(), 0.5f * (float) Math.random(), 0, 1);
            break;
          case FOCUSED:
            GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
            // FIXME: previously color3f
            shaders.setColor(1.0f, 1.0f, 1.0f, alpha / 255.0f);
            break;
          case FONT_PEOPLENAME:
            GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
            shaders.setColor(0.9f, 0.5f, 0.2f, alpha / 255.0f);
            break;
          default:
            color[3] = alpha / 255.0f;
            shaders.setColor(color[0], color[1], color[2], color[3]);
            GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
        }
        meshSprites[numBank].render(nbQuads);
        posBankOrder++;
      }
    }

    // Deactivate pixel shader
    if (pixelShaderSupported) {
      shaders.setCurrentShader(GLShaders.textured);
    }
    GLES20.glDisable(GLES20.GL_BLEND);

    gamma = (float) ((gamma + 0.01f) % (Math.PI * 2));
  }
  // The render function.
  private void renderFrame() {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    State state = mRenderer.begin();
    mRenderer.drawVideoBackground();

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    // handle face culling, we need to detect if we are using reflection
    // to determine the direction of the culling
    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glCullFace(GLES20.GL_BACK);
    if (Renderer.getInstance().getVideoBackgroundConfig().getReflection()
        == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)
      GLES20.glFrontFace(GLES20.GL_CW); // Front camera
    else GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

    // did we find any trackables this frame?
    for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {
      TrackableResult result = state.getTrackableResult(tIdx);
      Trackable trackable = result.getTrackable();
      printUserData(trackable);
      Matrix44F modelViewMatrix_Vuforia = Tool.convertPose2GLMatrix(result.getPose());
      float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();

      int textureIndex = trackable.getName().equalsIgnoreCase("cat") ? 0 : 1;
      textureIndex = trackable.getName().equals("city") ? 1 : textureIndex;
      textureIndex = trackable.getName().equalsIgnoreCase("tree") ? 2 : textureIndex;

      // Part B

      Calendar calendar = Calendar.getInstance();
      int day = calendar.get(Calendar.DAY_OF_WEEK);

      if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) {

        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_013")
                ? ImageTargets.orderImages.indexOf("b11_013") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_014")
                ? ImageTargets.orderImages.indexOf("b11_014") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_015")
                ? ImageTargets.orderImages.indexOf("b11_015") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("berkaer_003")
                ? ImageTargets.orderImages.indexOf("berkaer_003") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("p_013")
                ? ImageTargets.orderImages.indexOf("p_013") + 3
                : textureIndex;

      } else {
        textureIndex = trackable.getName().equalsIgnoreCase("b11_013") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("b11_014") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("b11_015") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("berkaer_003") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("p_013") ? 3 : textureIndex;
      }

      // deal with the modelview and projection matrices
      float[] modelViewProjection = new float[16];

      boolean partA =
          trackable.getName().equalsIgnoreCase("cat")
              || trackable.getName().equalsIgnoreCase("city")
              || trackable.getName().equalsIgnoreCase("tree");

      if (!mActivity.isExtendedTrackingActive()) {
        if (partA) {
          Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f, OBJECT_SCALE_FLOAT);
          Matrix.scaleM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        } else {
          Matrix.translateM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
          Matrix.scaleM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        }

      } else {
        Matrix.rotateM(modelViewMatrix, 0, 90.0f, 1.0f, 0, 0);
        Matrix.scaleM(modelViewMatrix, 0, kBuildingScale, kBuildingScale, kBuildingScale);
      }

      Matrix.multiplyMM(
          modelViewProjection,
          0,
          vuforiaAppSession.getProjectionMatrix().getData(),
          0,
          modelViewMatrix,
          0);

      // activate the shader program and bind the vertex/normal/tex coords
      GLES20.glUseProgram(shaderProgramID);

      if (!mActivity.isExtendedTrackingActive()) {

        if (partA) {
          GLES20.glVertexAttribPointer(
              vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mTeapot.getVertices());
          GLES20.glVertexAttribPointer(
              normalHandle, 3, GLES20.GL_FLOAT, false, 0, mTeapot.getNormals());
          GLES20.glVertexAttribPointer(
              textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());
        } else {

          Log.d("Object", "Name:" + trackable.getName());
          // To replace the Teapot for a plane Image

          GLES20.glVertexAttribPointer(
              vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mTextPlane.getVertices());
          GLES20.glVertexAttribPointer(
              normalHandle, 3, GLES20.GL_FLOAT, false, 0, mTextPlane.getNormals());
          GLES20.glVertexAttribPointer(
              textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTextPlane.getTexCoords());
        }

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        // activate texture 0, bind it, and pass to shader
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(textureIndex).mTextureID[0]);

        GLES20.glUniform1i(texSampler2DHandle, 0);

        // pass the model view matrix to the shader
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);

        if (partA) {
          // Finally draw the teapot
          GLES20.glDrawElements(
              GLES20.GL_TRIANGLES,
              mTeapot.getNumObjectIndex(),
              GLES20.GL_UNSIGNED_SHORT,
              mTeapot.getIndices());

        } else {
          // Draw the plane text
          GLES20.glDrawElements(
              GLES20.GL_TRIANGLES,
              mTextPlane.getNumObjectIndex(),
              GLES20.GL_UNSIGNED_SHORT,
              mTextPlane.getIndices());
        }

        // disable the enabled arrays
        GLES20.glDisableVertexAttribArray(vertexHandle);
        GLES20.glDisableVertexAttribArray(normalHandle);
        GLES20.glDisableVertexAttribArray(textureCoordHandle);
      } else {
        GLES20.glDisable(GLES20.GL_CULL_FACE);
        GLES20.glVertexAttribPointer(
            vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getVertices());
        GLES20.glVertexAttribPointer(
            normalHandle, 3, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getNormals());
        GLES20.glVertexAttribPointer(
            textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getTexCoords());

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(3).mTextureID[0]);
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);
        GLES20.glUniform1i(texSampler2DHandle, 0);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mBuildingsModel.getNumObjectVertex());

        SampleUtils.checkGLError("Renderer DrawBuildings");
      }

      SampleUtils.checkGLError("Render Frame");
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    mRenderer.end();
  }