Пример #1
0
  @Override
  public void onDrawEye(Eye eyeTransform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    checkGLError("colorParam");

    GLES20.glUseProgram(mProgram);
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    checkGLError("befor activeTex");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    checkGLError("after activeTex");
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
    checkGLError("bind Text");

    checkGLError("mPostionHandle");
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    checkGLError("mTexture Handle");
    mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate");
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);
    GLES20.glVertexAttribPointer(
        mTextureCoordHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        vertexStride,
        textureVerticesBuffer);
    checkGLError("after mTexture Handle");

    mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture");
    checkGLError("mColor Handel");

    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    checkGLError("Disable");
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordHandle);

    checkGLError("before Cube 2");
    Matrix.multiplyMM(mView, 0, eyeTransform.getEyeView(), 0, mCamera, 0);
    Matrix.multiplyMV(lightPosInEyeSpace, 0, mView, 0, LIGHT_POS_IN_WORLD_SPACE, 0);

    checkGLError("before Cube");
    float[] perspective = eyeTransform.getPerspective(Z_NEAR, Z_FAR);
    Matrix.multiplyMM(modelView, 0, mView, 0, mModelCube, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
    drawCube();
  }
Пример #2
0
  /**
   * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as a
   * parameter.
   *
   * @param transform The transformations to apply to render this eye.
   */
  @Override
  public void onDrawEye(EyeTransform transform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);

    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate");
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);
    GLES20.glVertexAttribPointer(
        mTextureCoordHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        vertexStride,
        textureVerticesBuffer);

    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordHandle);

    Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
  }
Пример #3
0
  public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

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

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

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

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

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

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

    // Draw the square
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
  void draw(Model m) {
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    int oldProgram = GLES20.GL_CURRENT_PROGRAM;
    GLES20.glUseProgram(program);
    GLES20.glEnableVertexAttribArray(aVertexHandle);
    GLES20.glEnableVertexAttribArray(aNormalHandle);

    GLES20.glVertexAttribPointer(aVertexHandle, 3, GLES20.GL_FLOAT, false, 0, m.vertexBuffer);
    GLES20.glVertexAttribPointer(aNormalHandle, 3, GLES20.GL_FLOAT, false, 0, m.normalBuffer);
    float[] modelViewMatrix = new float[16];
    Matrix.multiplyMM(modelViewMatrix, 0, modelMatrix, 0, viewMatrix, 0);
    GLES20.glUniformMatrix4fv(uMVMatrixHandle, 1, false, modelViewMatrix, 0);
    GLES20.glUniformMatrix4fv(uPMatrixHandle, 1, false, projectionMatrix, 0);

    // GLES20.glDrawArrays(mode, first, count)
    // if(m.indexBuffer != null)
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, m.num_indices, GLES20.GL_UNSIGNED_SHORT, m.indexBuffer);
    // else
    //	GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, m.num_indices);

    GLES20.glDisableVertexAttribArray(aNormalHandle);
    GLES20.glDisableVertexAttribArray(aVertexHandle);
    GLES20.glUseProgram(oldProgram);
  }
 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);
 }
Пример #6
0
  public void draw() {
    // Bind the array buffer using the handle we generated for the vertex buffer earlier,
    // to tell the graphics card which buffer we're talking about when we issue the next few
    // commands
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.mBufferHandles[0]);

    // Tell the graphics card how position data is stored in our vertex buffer, so the shader knows
    // where to get the data for the "position" attribute value in the shader
    GLES20.glEnableVertexAttribArray(GLES20Shader.ATTRIB_POSITION);
    GLES20.glVertexAttribPointer(GLES20Shader.ATTRIB_POSITION, 3, GLES20.GL_FLOAT, false, 8 * 4, 0);

    // Tell the graphics card how normal data is stored in our vertex buffer, so the shader knows
    // where to get the data for the "normal" attribute value in the shader
    GLES20.glEnableVertexAttribArray(GLES20Shader.ATTRIB_NORMAL);
    GLES20.glVertexAttribPointer(GLES20Shader.ATTRIB_NORMAL, 3, GLES20.GL_FLOAT, false, 8 * 4, 12);

    GLES20.glEnableVertexAttribArray(GLES20Shader.ATTRIB_TEXCOORD);
    GLES20.glVertexAttribPointer(
        GLES20Shader.ATTRIB_TEXCOORD, 2, GLES20.GL_FLOAT, false, 8 * 4, 24);

    // Bind the element buffer using the handle we generated for the element buffer earlier,
    // to tell the graphics card which buffer we're talking about when we issue the next few
    // commands
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, this.mBufferHandles[1]);

    // Issue a command to the graphics card, telling it to draw triangles using the provided data,
    // of which
    // there are mElements.capacity() total vertices, with the element data provided as unsigned
    // ints (4 bytes
    // per element value), and starting at offset 0 into the bound element array buffer
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, this.mElements.capacity(), GLES20.GL_UNSIGNED_INT, 0);
  }
Пример #7
0
  @Override
  public void draw(
      float[] mMVPMatrix, float[] mRotationMatrix, float[] mvMatrix, float[] mProjMatrix) {
    if (visible && canvasSurfaceCreated()) {

      if (!initialized) {
        if (!initObject()) {
          return;
        }
      }

      // Add program to OpenGL environment
      GLES20.glUseProgram(programHandle);

      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureDataHandle);

      GLES20.glUniform1i(textureUniformHandle, 0);

      // Enable a handle to the triangle vertices
      // Prepare the triangle coordinate data
      vBuffer.position(0);
      GLES20.glVertexAttribPointer(
          positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vBuffer);
      GLES20.glEnableVertexAttribArray(positionHandle);

      // Pass in the texture coordinate information
      textureBuffer.position(0);
      GLES20.glVertexAttribPointer(
          textureCoordinateHandle,
          COORDS_PER_TEXTURE,
          GLES20.GL_FLOAT,
          false,
          (COORDS_PER_TEXTURE * 4),
          textureBuffer);
      GLES20.glEnableVertexAttribArray(textureCoordinateHandle);

      Matrix.multiplyMM(mMVPMatrix, 0, mvMatrix, 0, mModelMatrix, 0);

      // Apply the projection and view transformation
      GLES20.glUniformMatrix4fv(mModelMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20Renderer.checkGLError("glUniformMatrix4fv");

      Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0);

      GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20Renderer.checkGLError("glUniformMatrix4fv");

      // Draw the square
      GLES20.glDrawElements(
          GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawBuffer);

      // Disable vertex array
      // GLES20.glDisableVertexAttribArray(positionHandle);
    }
  }
Пример #8
0
  public void draw(float[] matrix) {
    heightmapProgram.useProgram();
    heightmapProgram.setUniforms(matrix);
    bindData();

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.getBufferId());
    glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_SHORT, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  }
    @Override
    public void onDrawFrame(GL10 glUnused) {
      GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
      GLES20.glUseProgram(mProgram);
      checkGlError("glUseProgram");

      if (mBuffer != null) {
        synchronized (this) {
          GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureY[0]);
          GLES20.glTexImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              GLES20.GL_LUMINANCE,
              mBufferWidthY,
              mBufferHeightY,
              0,
              GLES20.GL_LUMINANCE,
              GLES20.GL_UNSIGNED_BYTE,
              mBuffer.position(mBufferPositionY));
          GLES20.glUniform1i(muSamplerYHandle, 0);

          GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureU[0]);
          GLES20.glTexImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              GLES20.GL_LUMINANCE,
              mBufferWidthUV,
              mBufferHeightUV,
              0,
              GLES20.GL_LUMINANCE,
              GLES20.GL_UNSIGNED_BYTE,
              mBuffer.position(mBufferPositionU));
          GLES20.glUniform1i(muSamplerUHandle, 1);

          GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureV[0]);
          GLES20.glTexImage2D(
              GLES20.GL_TEXTURE_2D,
              0,
              GLES20.GL_LUMINANCE,
              mBufferWidthUV,
              mBufferHeightUV,
              0,
              GLES20.GL_LUMINANCE,
              GLES20.GL_UNSIGNED_BYTE,
              mBuffer.position(mBufferPositionV));
          GLES20.glUniform1i(muSamplerVHandle, 2);
        }
      }

      GLES20.glDrawElements(
          GLES20.GL_TRIANGLES, INDICES_DATA.length, GLES20.GL_UNSIGNED_SHORT, mIndices);
    }
Пример #10
0
  @Override
  public void render(float[] mMVPMatrix, float[] mMVMatrix) {
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVMatrix, 0);

    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glEnableVertexAttribArray(mNormalHandle);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo[0]);
    GLES20.glVertexAttribPointer(
        mPositionHandle,
        POSITION_SIZE,
        GLES20.GL_FLOAT,
        false,
        BYTE_PER_FLOAT * (POSITION_SIZE + NORMAL_SIZE),
        0);
    GLES20.glVertexAttribPointer(
        mNormalHandle,
        POSITION_SIZE,
        GLES20.GL_FLOAT,
        false,
        BYTE_PER_FLOAT * (POSITION_SIZE + NORMAL_SIZE),
        BYTE_PER_FLOAT * POSITION_SIZE);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    for (int i = 0; i < 2; i++) {
      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo[i]);
      GLES20.glDrawElements(GLES20.GL_TRIANGLE_FAN, n * 2 + 2, GLES20.GL_UNSIGNED_SHORT, 0);
      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
    }

    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo[2]);
    for (int i = 0; i < (n * 2 + 1) * (n - 2) * 2; i += (n * 2 + 1) * 2) {
      GLES20.glDrawElements(
          GLES20.GL_TRIANGLE_STRIP, (n * 2 + 1) * 2, GLES20.GL_UNSIGNED_SHORT, BYTE_PER_SHORT * i);
    }
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
  }
Пример #11
0
  /**
   * Encapsulates the OpenGL ES instructions for drawing this shape.
   *
   * @param mvpMatrix - The Model View Project matrix in which to draw this shape.
   */
  public void draw(float[] mvpMatrix, boolean changeColor) {
    if (mProgram != 0) {
      // Add program to OpenGL environment
      GLES20.glUseProgram(mProgram);

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

      // Enable a handle to the triangle vertices
      GLES20.glEnableVertexAttribArray(mPositionHandle);

      // Get handle to fragment shader's vColor member
      mColor = GLES20.glGetAttribLocation(mProgram, "vColor");

      // Enable a handle to the color vertices
      GLES20.glEnableVertexAttribArray(mColor);

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

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

      // Prepare the coordinate data
      GLES20.glVertexAttribPointer(
          mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mVertexBuffer);

      // Prepare the color data
      if (changeColor) {
        GLES20.glVertexAttribPointer(
            mColor, COORDS_PER_COLORS, GLES20.GL_FLOAT, false, COLORS_STRIDE, mColor2Buffer);
      } else {
        GLES20.glVertexAttribPointer(
            mColor, COORDS_PER_COLORS, GLES20.GL_FLOAT, false, COLORS_STRIDE, mColor1Buffer);
      }

      // Draw the shape
      GLES20.glDrawElements(
          GLES20.GL_TRIANGLES, INDICES.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);

      // Disable vertex array
      GLES20.glDisableVertexAttribArray(mPositionHandle);
      // Disable color array
      GLES20.glDisableVertexAttribArray(mColor);
    }
  }
Пример #12
0
  /**
   * Encapsulates the OpenGL ES instructions for drawing this shape.
   *
   * @param mvpMatrix - The Model View Project matrix in which to draw this shape.
   */
  public void draw(float[] mvpMatrix, int eye) {
    // Add program to OpenGL environment
    GLES20.glUseProgram(mProgram);

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

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glEnableVertexAttribArray(mUVCoordsHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    GLES20.glVertexAttribPointer(mUVCoordsHandle, 2, GLES20.GL_FLOAT, true, 2 * 4, uvBuffer);

    int index = 0;
    int textureUnit = 0;
    if (eye == Eye.Type.LEFT) {
      index = 0;
    } else {
      index = 1;
    }

    textureUnit = GLES20.GL_TEXTURE0 + index;

    GLES20.glActiveTexture(textureUnit);
    GLES20.glUniform1i(mSamplerUniformHandle, index);

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

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

    // Draw the square
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mUVCoordsHandle);
  }
Пример #13
0
  private void draw(final FloatBuffer acubeBuffer, final int i) {

    // Pass in the position information. each vertex needs 3 values and each
    // face of the
    // cube needs 4 vertices. so total 3*4 = 12
    acubeBuffer.position(12 * i);
    GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, acubeBuffer);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information. every vertex colr is defined by 4 values and each cube face
    // has 4 vertices so 4*4 = 16
    mCubeColors.position(16 * i);
    GLES20.glVertexAttribPointer(mColorHandle, 4, GLES20.GL_FLOAT, false, 0, mCubeColors);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // Pass in the texture coordinate information. every vertex needs 2
    // values to define texture
    // for each face of the cube we need 4 textures . so 4*2=8
    mCubeTextureCoordinates.position(8 * i);
    GLES20.glVertexAttribPointer(
        mTextureCoordinateHandle,
        mTextureCoordinateDataSize,
        GLES20.GL_FLOAT,
        false,
        0,
        mCubeTextureCoordinates);

    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
    // This multiplies the view matrix by the model matrix, and stores the
    // result in the MVP matrix
    // (which currently contains model * view).
    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

    // This multiplies the modelview matrix by the projection matrix, and
    // stores the result in the MVP matrix
    // (which now contains model * view * projection).
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    // *each face of the cube is drawn using 2 triangles. so 2*3=6 lines
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, indexBuffer);
  }
Пример #14
0
  public void Draw(float[] viewProjectionMatrix, int textureName) {
    GLES20.glUseProgram(shaderProgram);
    // set position
    int aPosition = GLES20.glGetAttribLocation(shaderProgram, "aPosition");
    GLES20.glEnableVertexAttribArray(aPosition);
    GLES20.glVertexAttribPointer(aPosition, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);

    // set textcoord
    int aTexcoord = GLES20.glGetAttribLocation(shaderProgram, "aTexcoord");
    GLES20.glEnableVertexAttribArray(aTexcoord);
    GLES20.glVertexAttribPointer(aTexcoord, 2, GLES20.GL_FLOAT, false, 0, textureCoordinatesBuffer);

    // set matrix Projection * View * Rotation * world
    Matrix.multiplyMM(worldViewProjectionMatrix, 0, viewProjectionMatrix, 0, worldMatrix, 0);
    int mat4x4 = GLES20.glGetUniformLocation(shaderProgram, "matrix");
    GLES20.glUniformMatrix4fv(mat4x4, 1, false, worldViewProjectionMatrix, 0);

    int uTemp = GLES20.glGetUniformLocation(shaderProgram, "uTemp");

    if (textureName != 0) {
      GLES20.glUniform1f(uTemp, 1.0f);

      int uTexture = GLES20.glGetUniformLocation(shaderProgram, "uTexture");
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureName);
      GLES20.glUniform1i(uTexture, 0);

      int uTexture2 = GLES20.glGetUniformLocation(shaderProgram, "uTexture2");
      GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture.getName());
      GLES20.glUniform1i(uTexture2, 1);

    } else GLES20.glUniform1f(uTemp, 0.0f);

    // Draw Cube
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLE_STRIP, index.length, GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    // Disable attribute
    GLES20.glDisableVertexAttribArray(aPosition);
    GLES20.glDisableVertexAttribArray(aTexcoord);
  }
Пример #15
0
  @Override
  public void drawElements(final int mode, final int count, final IShortBuffer indices) {
    checkOpenGLThread();

    final ShortBuffer indexBuffer = ((ShortBuffer_Android) indices).getBuffer();

    //      System.err.println("drawElements(mode=" + mode + //
    //                         ", count=" + count + //
    //                         ", indexBuffer=" + indexBuffer + ")");

    GLES20.glDrawElements(mode, count, GLES20.GL_UNSIGNED_SHORT, indexBuffer);

    //      final ShortBuffer_Android bufferAndroid = (ShortBuffer_Android) indices;
    //      final int webGLBuffer = bufferAndroid.getGLBuffer();
    //      GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, webGLBuffer);
    //
    //      final Buffer array = bufferAndroid.getBuffer();
    //      GLES20.glBufferData(GLES20.GL_ELEMENT_ARRAY_BUFFER, count, array,
    // GLES20.GL_STATIC_DRAW);
    //
    //      GLES20.glDrawElements(mode, count, GLES20.GL_UNSIGNED_SHORT, 0);
  }
 private void renderDistortionMesh(final DistortionMesh mesh, final int textureId) {
   ProgramHolder holder;
   if (this.mChromaticAberrationCorrectionEnabled) {
     holder = this.mProgramHolderAberration;
   } else {
     holder = this.mProgramHolder;
   }
   GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mesh.mArrayBufferId);
   GLES20.glVertexAttribPointer(holder.aPosition, 2, GLES20.GL_FLOAT, false, 36, 0 * 4);
   GLES20.glEnableVertexAttribArray(holder.aPosition);
   GLES20.glVertexAttribPointer(holder.aVignette, 1, GLES20.GL_FLOAT, false, 36, 2 * 4);
   GLES20.glEnableVertexAttribArray(holder.aVignette);
   GLES20.glVertexAttribPointer(holder.aBlueTextureCoord, 2, GLES20.GL_FLOAT, false, 36, 7 * 4);
   GLES20.glEnableVertexAttribArray(holder.aBlueTextureCoord);
   if (this.mChromaticAberrationCorrectionEnabled) {
     GLES20.glVertexAttribPointer(
         ((ProgramHolderAberration) holder).aRedTextureCoord,
         2,
         GLES20.GL_FLOAT,
         false,
         36,
         3 * 4);
     GLES20.glEnableVertexAttribArray(((ProgramHolderAberration) holder).aRedTextureCoord);
     GLES20.glVertexAttribPointer(
         ((ProgramHolderAberration) holder).aGreenTextureCoord,
         2,
         GLES20.GL_FLOAT,
         false,
         36,
         5 * 4);
     GLES20.glEnableVertexAttribArray(((ProgramHolderAberration) holder).aGreenTextureCoord);
   }
   GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
   GLES20.glUniform1i(this.mProgramHolder.uTextureSampler, 0);
   GLES20.glUniform1f(this.mProgramHolder.uTextureCoordScale, this.mResolutionScale);
   GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mesh.mElementBufferId);
   GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, mesh.nIndices, GLES20.GL_UNSIGNED_SHORT, 0);
 }
  private void drawCar(int program, float[] startPos) {
    Matrix.setIdentityM(mMMatrix, 0);
    Matrix.setIdentityM(mTransMatrix, 0);

    // Képernyõ Y tengely
    if (Math.abs(mDY) < 2) mDY = 0;

    if (Math.abs(mDY) <= 250) {
      accelY = -1 * mDY * 2;
    } else {
      if (mDY < 0) mDY = -250f;
      if (mDY > 0) mDY = 250f;
    }
    distanceY += accelY;
    Log.d("mDY:", String.valueOf(mDY));

    // Képernyõ X tengely
    if (Math.abs(mDX) < 2) mDX = 0;
    float[] forward = {(float) Math.cos(mDX / 50), 0.0f, (float) Math.sin(mDX / 50)};

    // lookAt
    lookAt[0] = eyePos[0] + 25 * forward[0];
    lookAt[1] = eyePos[1] + 25 * forward[1];
    lookAt[2] = eyePos[2] + 25 * forward[2];

    // eyePos
    eyePos[0] = 0.0f + distanceY / 1000 * forward[0];
    eyePos[2] = 25.0f + distanceY / 1000 * forward[2];

    Matrix.setLookAtM(
        mVMatrix, 0, eyePos[0], eyePos[1], eyePos[2], lookAt[0], lookAt[1], lookAt[2], 0.0f, 1.0f,
        0.0f);

    // Kormányzás
    startPos[0] = eyePos[0] + 5 * forward[0];
    startPos[2] = eyePos[2] + 5 * forward[2];

    Matrix.translateM(mTransMatrix, 0, startPos[0], startPos[1], startPos[2]);

    Matrix.multiplyMM(mMMatrix, 0, mMMatrix, 0, mTransMatrix, 0); // Translate
    Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); // View
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); // Proj

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "uMVPMatrix"), 1, false, mMVPMatrix, 0);

    // Create the normal modelview matrix
    // Invert + transpose of mvpmatrix
    Matrix.invertM(normalMatrix, 0, mMVPMatrix, 0);
    Matrix.transposeM(normalMatrix, 0, normalMatrix, 0);

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "normalMatrix"), 1, false, mMVPMatrix, 0);

    /** * DRAWING OBJECT * */
    // Get buffers from mesh
    Object3D ob = this._objects[this.CUBE];
    Mesh mesh = ob.getMesh();
    FloatBuffer _vb = mesh.get_vb();
    ShortBuffer _ib = mesh.get_ib();

    short[] _indices = mesh.get_indices();

    // Vertex buffer

    // the vertex coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aPosition"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aPosition"));

    // the normal info
    _vb.position(TRIANGLE_VERTICES_DATA_NOR_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aNormal"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aNormal"));

    // Texture info

    // bind textures
    if (ob.hasTexture()) { // && enableTexture) {
      // number of textures
      int[] texIDs = ob.get_texID();

      for (int i = 0; i < _texIDs.length; i++) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
        // Log.d("TEXTURE BIND: ", i + " " + texIDs[i]);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIDs[i]);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "texture" + (i + 1)), i);
      }
    }

    // enable texturing? [fix - sending float is waste]
    GLES20.glUniform1f(
        GLES20.glGetUniformLocation(program, "hasTexture") /*shader.hasTextureHandle*/,
        ob.hasTexture() && enableTexture ? 2.0f : 0.0f);

    // texture coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_TEX_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "textureCoord") /*shader.maTextureHandle*/,
        2,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(
        GLES20.glGetAttribLocation(
            program, "textureCoord")); // GLES20.glEnableVertexAttribArray(shader.maTextureHandle);

    // Draw with indices
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, _indices.length, GLES20.GL_UNSIGNED_SHORT, _ib);
    checkGlError("glDrawElements");

    /** END DRAWING OBJECT ** */
  }
Пример #18
0
 @Override
 public void glDrawElements(int mode, int count, int type, int offset) {
   GLES20.glDrawElements(mode, count, type, offset);
 }
Пример #19
0
 @Override
 public void glDrawElements(int mode, int count, int type, Buffer indices) {
   GLES20.glDrawElements(mode, count, type, indices);
 }
Пример #20
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);
  }
Пример #21
0
 public void draw() {
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.getBufferId());
   glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_SHORT, 0);
   glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 }
Пример #22
0
  public void draw(float[] mvMatrix, float[] pMatrix) {
    float[] normalMatrix = new float[16];
    float[] tmpMatrix = new float[16];
    Matrix.invertM(tmpMatrix, 0, mvMatrix, 0);
    Matrix.transposeM(normalMatrix, 0, tmpMatrix, 0);

    // Add program to OpenGL ES environment
    GLES20.glUseProgram(shaderProgram);

    // vertex position attribute array
    int mPositionHandle = GLES20.glGetAttribLocation(shaderProgram, "vPosition");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    // vertex normal attribute array
    int mNormalHandle = GLES20.glGetAttribLocation(shaderProgram, "vNormal");
    GLES20.glEnableVertexAttribArray(mNormalHandle);
    GLES20.glVertexAttribPointer(
        mNormalHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, normalBuffer);

    // vertex UV attribute array
    int mUVHandle = GLES20.glGetAttribLocation(shaderProgram, "vTexCoord");
    GLES20.glEnableVertexAttribArray(mUVHandle);
    GLES20.glVertexAttribPointer(mUVHandle, 2, GLES20.GL_FLOAT, false, 8, uvBuffer);

    // material data
    int mColorHandle = GLES20.glGetUniformLocation(shaderProgram, "Color");
    int mAmbientHandle = GLES20.glGetUniformLocation(shaderProgram, "Ambient");
    int mDiffuseHandle = GLES20.glGetUniformLocation(shaderProgram, "Diffuse");
    int mSpecularHandle = GLES20.glGetUniformLocation(shaderProgram, "Specular");
    int mShininessHandle = GLES20.glGetUniformLocation(shaderProgram, "Shininess");
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);
    GLES20.glUniform3fv(mAmbientHandle, 1, ambient, 0);
    GLES20.glUniform3fv(mDiffuseHandle, 1, diffuse, 0);
    GLES20.glUniform3fv(mSpecularHandle, 1, specular, 0);
    GLES20.glUniform1f(mShininessHandle, shininess);

    // transformation matrices
    int mMVMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "MVMatrix");
    int mPMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "PMatrix");
    int mNormalMatrixHandle = GLES20.glGetUniformLocation(shaderProgram, "NormalMatrix");
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mvMatrix, 0);
    GLES20.glUniformMatrix4fv(mPMatrixHandle, 1, false, pMatrix, 0);
    GLES20.glUniformMatrix4fv(mNormalMatrixHandle, 1, false, normalMatrix, 0);

    // lighting data
    int mLightPosHandle = GLES20.glGetUniformLocation(shaderProgram, "LightPos");
    int mLightColorHandle = GLES20.glGetUniformLocation(shaderProgram, "LightColor");
    GLES20.glUniform4fv(mLightPosHandle, 1, lightPosition, 0);
    GLES20.glUniform3fv(mLightColorHandle, 1, lightColor, 0);

    // texture
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
    int mTexHandle = GLES20.glGetUniformLocation(shaderProgram, "Tex");
    GLES20.glUniform1i(mTexHandle, 0);

    // Draw the object
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable arrays
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mNormalHandle);
    GLES20.glDisableVertexAttribArray(mUVHandle);
  }
  private void drawRoad(int program) {
    Matrix.setIdentityM(mMMatrix, 0);

    Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); // View
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); // Proj

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "uMVPMatrix"), 1, false, mMVPMatrix, 0);

    // Create the normal modelview matrix
    // Invert + transpose of mvpmatrix
    Matrix.invertM(normalMatrix, 0, mMVPMatrix, 0);
    Matrix.transposeM(normalMatrix, 0, normalMatrix, 0);

    // send to the shader
    GLES20.glUniformMatrix4fv(
        GLES20.glGetUniformLocation(program, "normalMatrix"), 1, false, mMVPMatrix, 0);

    /** * DRAWING OBJECT * */
    // Get buffers from mesh
    Object3D ob = this._objects[this.ROAD];
    Mesh mesh = ob.getMesh();
    FloatBuffer _vb = mesh.get_vb();
    ShortBuffer _ib = mesh.get_ib();

    short[] _indices = mesh.get_indices();

    /*float[] myVertices = {
    	-20, 0, -20,
    	-20f, 0, 20,
    	20, 0, -20,
    	20, 0, 20
    };

    _vb = ByteBuffer.allocateDirect(myVertices.length
    		* FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
    _vb.put(myVertices);*/

    // Vertex buffer

    // the vertex coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aPosition"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aPosition"));

    // the normal info
    _vb.position(TRIANGLE_VERTICES_DATA_NOR_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "aNormal"),
        3,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(program, "aNormal"));

    // Texture info

    // bind textures
    if (ob.hasTexture()) { // && enableTexture) {
      // number of textures
      int[] texIDs = ob.get_texID();

      for (int i = 0; i < _texIDs.length; i++) {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
        // Log.d("TEXTURE BIND: ", i + " " + texIDs[i]);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIDs[i]);
        GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "texture" + (i + 1)), i);
      }
    }

    // enable texturing? [fix - sending float is waste]
    GLES20.glUniform1f(
        GLES20.glGetUniformLocation(program, "hasTexture") /*shader.hasTextureHandle*/,
        ob.hasTexture() && enableTexture ? 2.0f : 0.0f);

    // texture coordinates
    _vb.position(TRIANGLE_VERTICES_DATA_TEX_OFFSET);
    GLES20.glVertexAttribPointer(
        GLES20.glGetAttribLocation(program, "textureCoord") /*shader.maTextureHandle*/,
        2,
        GLES20.GL_FLOAT,
        false,
        TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
        _vb);
    GLES20.glEnableVertexAttribArray(
        GLES20.glGetAttribLocation(
            program, "textureCoord")); // GLES20.glEnableVertexAttribArray(shader.maTextureHandle);

    // Draw with indices
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, _indices.length, GLES20.GL_UNSIGNED_SHORT, _ib);
    checkGlError("glDrawElements");

    /** END DRAWING OBJECT ** */
  }
  /**
   * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as a
   * parameter.
   *
   * @param transform The transformations to apply to render this eye.
   */
  @Override
  public void onDrawEye(EyeTransform transform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);

    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate");
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);
    GLES20.glVertexAttribPointer(
        mTextureCoordHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        vertexStride,
        textureVerticesBuffer);

    mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture");

    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordHandle);

    Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);

    //        mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
    //        mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
    //        mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
    //
    //        GLES20.glEnableVertexAttribArray(mPositionParam);
    //        GLES20.glEnableVertexAttribArray(mNormalParam);
    //        GLES20.glEnableVertexAttribArray(mColorParam);
    //        checkGLError("mColorParam");
    //
    //        // Apply the eye transformation to the camera.
    //        Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
    //
    //        // Set the position of the light
    //        Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0);
    //        GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1],
    //                mLightPosInEyeSpace[2]);
    //
    //        // Build the ModelView and ModelViewProjection matrices
    //        // for calculating cube position and light.
    //        Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0);
    //        Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView,
    // 0);
    //        drawCube();
    //
    //        // Set mModelView for the floor, so we draw floor in the correct location
    //        Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
    //        Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0,
    //            mModelView, 0);
    //        drawFloor(transform.getPerspective());
  }
Пример #25
0
  public void draw(StandardProgram prog, Viewport vp) {

    // get handle to vertex shader's vPosition member
    mPositionHandle = prog.getAttributeLocation("vPosition");

    // set the vertext pointer to the front of the buffer
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[0]);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, buffers[1]); // draw order

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // get handle to fragment shader's vColor member
    mColorHandle = prog.getUniformLocation("vColor");

    // texture stuff

    mTextureUniformHandle = prog.getUniformLocation("u_Texture");
    mTextureCoordinateHandle = prog.getAttributeLocation("a_TexCoordinate");
    tm.setTextureToRepeat(R.drawable.blank);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

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

    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = prog.getUniformLocation("uMVPMatrix");

    // start the position at -1, -1
    Matrix.setIdentityM(mMMatrix, 0);
    Matrix.translateM(mMMatrix, 0, 0, 0, 1.0f); // z index is at the very front

    // ---- draw a puddle

    setBufferPosition(PUDDLE);
    setColor(normalColor);

    setDrawPosition(300f, -300f);

    setScale(9.0f, 7.0f);

    // set up the view matrix and projection matrix
    Matrix.multiplyMM(eyeMatrix, 0, vp.getViewMatrix(), 0, mMMatrix, 0);
    Matrix.multiplyMM(mvpMatrix, 0, vp.getProjMatrix(), 0, eyeMatrix, 0);

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

    // Draw
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, 0);

    // ---- end draw puddle

    // IMPORTANT: Unbind from the buffer when we're done with it.
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
  // 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();
  }
Пример #27
0
 public void drawElements() {
   GLES20.glDrawElements(
       GLES20.GL_TRIANGLE_STRIP, mIndexBufferSize,
       GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
 }