Example #1
0
  public void drawSelf() {

    MatrixState.rotate(xAngle, 1, 0, 0); // 绕X轴转动
    MatrixState.rotate(yAngle, 0, 1, 0); // 绕Y轴转动
    MatrixState.rotate(zAngle, 0, 0, 1); // 绕Z轴转动
    // 制定使用某套着色器程序
    GLES20.glUseProgram(mProgram);
    // 将最终变换矩阵传入着色器程序
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
    // 将位置、旋转变换矩阵传入着色器程序
    GLES20.glUniformMatrix4fv(muMMatrixHandle, 1, false, MatrixState.getMMatrix(), 0);
    // 将光源位置传入着色器程序
    GLES20.glUniform3fv(maLightLocationHandle, 1, MatrixState.lightPositionFB);
    // 将摄像机位置传入着色器程序
    GLES20.glUniform3fv(maCameraHandle, 1, MatrixState.cameraFB);

    // 将顶点经纬度数据传入渲染管线
    GLES20.glVertexAttribPointer(maLongLatHandle, 2, GLES20.GL_FLOAT, false, 2 * 4, mLongLatBuffer);
    // 将顶点位置数据传入渲染管线
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer);
    // 将顶点法向量数据传入渲染管线
    GLES20.glVertexAttribPointer(maNormalHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mNormalBuffer);

    // 启用顶点位置、顶点经纬度数据
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    GLES20.glEnableVertexAttribArray(maNormalHandle); // 启用顶点法向量数据
    GLES20.glEnableVertexAttribArray(maLongLatHandle);
    // 绘制球
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
  }
  /**
   * Method for painting any given object. Data must be 7 floats per face – we render one triangle
   * consisting of 3 vertices with each vertice having an rgba color float value.
   *
   * @param data The vertice data containing coordinates and colors to draw.
   */
  private void drawObject(final FloatBuffer data) {

    // Pass in the position information
    data.position(mPositionOffset);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, mStrideBytes, data);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    data.position(mColorOffset);
    GLES20.glVertexAttribPointer(
        mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false, mStrideBytes, data);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // 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);
    // The (1+data.capacity() / 8) tells us how many vertices we need to
    // draw
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, (1 + data.capacity() / 8));
  }
  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);
  }
Example #4
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);
  }
  public static void bindPillowTexture(int color, int state, int deathTimeCounter, int direction) {
    if (state == ALIVE || state == BORNING) {

      if (direction == DIR_LEFT)
        GLES20.glVertexAttribPointer(
            Render.maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, Render.rect1TexCoordsBuf);
      else if (direction == DIR_UP)
        GLES20.glVertexAttribPointer(
            Render.maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, Render.rect2TexCoordsBuf);
      else if (direction == DIR_RIGHT)
        GLES20.glVertexAttribPointer(
            Render.maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, Render.rect3TexCoordsBuf);
      else if (direction == DIR_DOWN)
        GLES20.glVertexAttribPointer(
            Render.maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, Render.rect4TexCoordsBuf);
      //

      if (color == COLOR_GREY) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, Render.charGreyTexID);
      } else if (color == COLOR_RED) {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, Render.charRedTexID);
      }
    } else {
      findDyingTexture(direction, color, deathTimeCounter);
    }

    Render.quadTCBinded = false;
  }
  public void drawSelf(int texId) {
    // 制定使用某套shader程序
    GLES20.glUseProgram(mProgram);
    // 将最终变换矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
    // 将位置、旋转变换矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muMMatrixHandle, 1, false, MatrixState.getMMatrix(), 0);
    // 将摄像机位置传入shader程序
    GLES20.glUniform3fv(maCameraHandle, 1, MatrixState.cameraFB);
    // 将光源位置传入shader程序
    GLES20.glUniform3fv(maLightLocationHandle, 1, MatrixState.lightPositionFB);

    // 传送顶点位置数据
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer);
    // 传送顶点纹理坐标数据
    GLES20.glVertexAttribPointer(maTexCoorHandle, 2, GLES20.GL_FLOAT, false, 2 * 4, mTexCoorBuffer);
    // 传送顶点法向量数据
    GLES20.glVertexAttribPointer(maNormalHandle, 4, GLES20.GL_FLOAT, false, 3 * 4, mNormalBuffer);

    // 启用顶点位置数据
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    // 启用顶点纹理数据
    GLES20.glEnableVertexAttribArray(maTexCoorHandle);
    // 启用顶点法向量数据
    GLES20.glEnableVertexAttribArray(maNormalHandle);
    // 绑定纹理
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);

    // 绘制纹理矩形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
  }
  public void onDraw(
      final int textureId, final FloatBuffer cubeBuffer, final FloatBuffer textureBuffer) {
    GLES20.glUseProgram(mGLProgId);
    runPendingOnDrawTasks();
    if (!mIsInitialized) {
      return;
    }

    cubeBuffer.position(0);
    GLES20.glVertexAttribPointer(mGLAttribPosition, 2, GLES20.GL_FLOAT, false, 0, cubeBuffer);
    GLES20.glEnableVertexAttribArray(mGLAttribPosition);
    textureBuffer.position(0);
    GLES20.glVertexAttribPointer(
        mGLAttribTextureCoordinate, 2, GLES20.GL_FLOAT, false, 0, textureBuffer);
    GLES20.glEnableVertexAttribArray(mGLAttribTextureCoordinate);
    if (textureId != OpenGlUtils.NO_TEXTURE) {
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
      GLES20.glUniform1i(mGLUniformTexture, 0);
    }
    onDrawArraysPre();
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(mGLAttribPosition);
    GLES20.glDisableVertexAttribArray(mGLAttribTextureCoordinate);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
  }
  public void onSurfaceChanged(GL10 unused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);

    ratio = (float) width / height;

    // this projection matrix is applied to object coodinates
    // in the onDrawFrame() method
    Matrix.orthoM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    engine.initGL();

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    GLES20.glUniform1i(mSampleHandle, 0);
    GLES20.glUniform1f(mOpacityHandle, 1f);

    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 12, quadCoordsBuf);
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    GLES20.glVertexAttribPointer(maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, quadTexCoordsBuf);
    GLES20.glEnableVertexAttribArray(maTexCoordsHandle);

    initTextures();
  }
  @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);
  }
Example #10
0
  /** Constructor this should be called in GL context */
  public GLDrawer2D() {
    pVertex =
        ByteBuffer.allocateDirect(VERTEX_SZ * FLOAT_SZ)
            .order(ByteOrder.nativeOrder())
            .asFloatBuffer();
    pVertex.put(VERTICES);
    pVertex.flip();
    pTexCoord =
        ByteBuffer.allocateDirect(VERTEX_SZ * FLOAT_SZ)
            .order(ByteOrder.nativeOrder())
            .asFloatBuffer();
    pTexCoord.put(TEXCOORD);
    pTexCoord.flip();

    hProgram = loadShader(vss, fss);
    GLES20.glUseProgram(hProgram);
    maPositionLoc = GLES20.glGetAttribLocation(hProgram, "aPosition");
    maTextureCoordLoc = GLES20.glGetAttribLocation(hProgram, "aTextureCoord");
    muMVPMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uMVPMatrix");
    muTexMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uTexMatrix");

    Matrix.setIdentityM(mMvpMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mMvpMatrix, 0);
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, mMvpMatrix, 0);
    GLES20.glVertexAttribPointer(maPositionLoc, 2, GLES20.GL_FLOAT, false, VERTEX_SZ, pVertex);
    GLES20.glVertexAttribPointer(
        maTextureCoordLoc, 2, GLES20.GL_FLOAT, false, VERTEX_SZ, pTexCoord);
    GLES20.glEnableVertexAttribArray(maPositionLoc);
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);
  }
Example #11
0
  public void drawCube() {

    GLES20.glUseProgram(cubeProgram);
    checkGLError("Use program");

    GLES20.glUniform3fv(cubeLightPosParam, 1, lightPosInEyeSpace, 0);

    // Set the Model in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(cubeModelParam, 1, false, mModelCube, 0);

    // Set the ModelView in the shader, used to calculate lighting
    GLES20.glUniformMatrix4fv(cubeModelViewParam, 1, false, modelView, 0);

    // Set the position of the cube
    GLES20.glVertexAttribPointer(
        cubePositionParam, COORDS_PER_VERTEX_CUBE, GLES20.GL_FLOAT, false, 0, cubeVertices);

    // Set the ModelViewProjection matrix in the shader.
    GLES20.glUniformMatrix4fv(cubeModelViewProjectionParam, 1, false, modelViewProjection, 0);

    // Set the normal positions of the cube, again for shading
    GLES20.glVertexAttribPointer(cubeNormalParam, 3, GLES20.GL_FLOAT, false, 0, cubeNormals);
    GLES20.glVertexAttribPointer(cubeColorParam, 4, GLES20.GL_FLOAT, false, 0, cubeColors);

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

    checkGLError("Drawing cube");
  }
Example #12
0
  public void drawSelf(int texId) {
    MatrixState.rotate(xAngle, 1, 0, 0);
    MatrixState.rotate(yAngle, 0, 1, 0);
    MatrixState.rotate(zAngle, 0, 0, 1);

    // 制定使用某套shader程序
    GLES20.glUseProgram(mProgram);

    // 将最终变换矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);

    // 传送顶点位置数据
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer);
    // 传送顶点纹理坐标数据
    GLES20.glVertexAttribPointer(maTexCoorHandle, 2, GLES20.GL_FLOAT, false, 2 * 4, mTexCoorBuffer);

    // 启用顶点位置数据
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    // 启用顶点纹理数据
    GLES20.glEnableVertexAttribArray(maTexCoorHandle);

    // 绑定纹理
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);

    // 绘制纹理矩形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
  }
Example #13
0
  public void draw(final int mShader) {

    // Bind Texture VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, getTexVBO());
    // Pass in texture map position
    mTexVertBuffer.position(0);
    final int mTextureCoordinateHandle = GLES20.glGetAttribLocation(mShader, "a_TexCoord");
    GLES20.glVertexAttribPointer(
        mTextureCoordinateHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    // Bind VBO
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, getPlaneVBO());
    // Pass in the position information
    mPlaneVertBuffer.position(0);
    final int mPositionHandle = GLES20.glGetAttribLocation(mShader, "a_Position");
    GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    //	Pass in the color information
    final int mColorHandle = GLES20.glGetUniformLocation(mShader, "u_Color");
    GLES20.glUniform4f(mColorHandle, 0, 1, 1, 1);

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

    // Unbind buffers
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
    GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
  }
Example #14
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);
  }
Example #15
0
  public void draw() {
    // 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 scene vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

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

    // get handle to fragment shader's vColor member
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
    // Set colorVertices for drawing the scene
    GLES20.glUniform4fv(mColorHandle, 1, colorVertices, 0);

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

    // Apply the projection and view transformation
    GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, pointsRenderer.mtrxProjectionAndView, 0);

    // Draw the scene
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, vertexCount);

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

    if (drawLines) {
      GLES20.glUseProgram(mLinesProgram);
      mLinesPositionHandle = GLES20.glGetAttribLocation(mLinesProgram, "vPosition");
      GLES20.glEnableVertexAttribArray(mLinesPositionHandle);
      // Prevent null pointer race condition
      if (linesVertexBuffer != null) {
        GLES20.glVertexAttribPointer(
            mLinesPositionHandle,
            COORDS_PER_VERTEX,
            GLES20.GL_FLOAT,
            false,
            VERTEX_STRIDE,
            linesVertexBuffer);
        mLinesColorHandle = GLES20.glGetUniformLocation(mLinesProgram, "vColor");
        GLES20.glUniform4fv(mLinesColorHandle, 1, colorLines, 0);
        int mtrxLineshandle = GLES20.glGetUniformLocation(mLinesProgram, "uMVPMatrix");
        GLES20.glUniformMatrix4fv(
            mtrxLineshandle, 1, false, pointsRenderer.mtrxProjectionAndView, 0);
        // GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, linesVertexCount);
        // GLES20.glDrawArrays(GLES20.GL_LINES, 0, linesVertexCount);
        // GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, linesVertexCount);
        // GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, linesVertexCount);
        GLES20.glDrawArrays(renderMethod, 0, linesVertexCount);
        GLES20.glDisableVertexAttribArray(mLinesPositionHandle);
      }
    }
  }
Example #16
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);
    }
  }
  /** Draws a cube. */
  private void drawCube() {
    // Pass in the position information
    mCubePositions.position(0);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, mCubePositions);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    mCubeColors.position(0);
    GLES20.glVertexAttribPointer(
        mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false, 0, mCubeColors);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // Pass in the normal information
    mCubeNormals.position(0);
    GLES20.glVertexAttribPointer(
        mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false, 0, mCubeNormals);

    GLES20.glEnableVertexAttribArray(mNormalHandle);

    // Pass in the texture coordinate information
    mCubeTextureCoordinates.position(0);
    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);

    // Pass in the modelview matrix.
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 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);

    // Pass in the combined matrix.
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    // Pass in the light position in eye space.
    GLES20.glUniform3f(
        mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

    // Draw the cube.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
  }
    public void onDrawFrame(GL10 glUnused) {

      synchronized (this) {
        if (updateSurface) {
          mSurface.updateTexImage();
          mSurface.getTransformMatrix(mSTMatrix);
          updateSurface = false;
        } else {
          return;
        }
      }

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

      GLES20.glUseProgram(mProgram);
      checkGlError("glUseProgram");

      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);

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

      mTextureVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
      GLES20.glVertexAttribPointer(
          maTextureHandle,
          2,
          GLES20.GL_FLOAT,
          false,
          TEXTURE_VERTICES_DATA_STRIDE_BYTES,
          mTextureVertices);

      checkGlError("glVertexAttribPointer maTextureHandle");
      GLES20.glEnableVertexAttribArray(maTextureHandle);
      checkGlError("glEnableVertexAttribArray maTextureHandle");

      Matrix.setIdentityM(mMVPMatrix, 0);

      GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);

      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
      checkGlError("glDrawArrays");
      GLES20.glFinish();
    }
Example #19
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();
  }
  public void draw(GL10 gl) {
    // Set our vertex/frag shader program.
    GLES20.glUseProgram(mProgram);

    // Set program handles for drawing.
    // mPositionHandle = GLES20.glGetAttribLocation(mProgram, "a_Position");
    // mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgram, "a_TexCoordinate");
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgram, "u_Texture");
    // Set the active texture unit to texture unit 0.
    // GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    // Bind the texture to this unit.
    // GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    vertexBuffer.rewind();
    textureBuffer.rewind();

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit
    // 0.
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    // Point to our buffers
    // gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    // gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // Point to our vertex buffer
    // gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    // gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBufferPointer);
    // first parameter is the ID number of the attribute of the vertex
    // we set attribute id = 0 to the position and 1 to the texture coordin
    GLES20.glVertexAttribPointer(0, 3, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, textureBufferPointer);
    GLES20.glVertexAttribPointer(1, 2, GLES20.GL_FLOAT, false, 0, 0);
    GLES20.glEnableVertexAttribArray(1);

    // Set the face rotation
    // GLES20.glFrontFace(GL10.GL_CW);

    // Draw the vertices as triangle strip
    GLES20.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

    System.out.println(GLUtils.getEGLErrorString(gl.glGetError()));

    // Disable the client state before leaving
    // gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    // gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

  }
  /**
   * 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);
    }
  }
  /**
   * 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);
  }
Example #23
0
  public void drawSphere(final FloatBuffer aSphereBuffer) {
    aSphereBuffer.position(mPositionOffset);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, aSphereBuffer);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    //        aTriangleBuffer.position(mColorOffset);
    //        GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
    //        		mStrideBytes, aTriangleBuffer);
    //
    //        GLES20.glEnableVertexAttribArray(mColorHandle);

    // 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);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, sphereTriangles * 3);
  }
Example #24
0
  public void draw() {

    // Add program to OpenGLES 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, mVertexStride, mVertexBuffer);

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

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

    // draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mVertexCount);

    // disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
Example #25
0
  public void GenerateVertexArray(
      float[] arrayBuffer, int bufferSize, int valuesPerElement, int attributeNumber) {
    FloatBuffer.allocate(arrayBuffer.length);
    FloatBuffer bufferData =
        ByteBuffer.allocateDirect(bufferSize).order(ByteOrder.nativeOrder()).asFloatBuffer();
    bufferData.put(arrayBuffer).position(0);

    IntBuffer bufferID = (IntBuffer.allocate(1));
    bufferID.position(0);

    GLES20.glGenBuffers(1, bufferID);
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, bufferID.get(0));
    GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, bufferSize, bufferData, GLES20.GL_STATIC_DRAW);

    GLES20.glVertexAttribPointer(
        attributeNumber, // attribute
        valuesPerElement, // size
        GLES20.GL_FLOAT, // type
        false, // normalized?
        valuesPerElement * FLOAT_SIZE_BYTES, // stride
        0 // array buffer offset
        );

    vertexArrayList.add(new GLVertexArrayObject(bufferID.get(), attributeNumber, valuesPerElement));
  }
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    int program = GLES20.glCreateProgram();
    addShaderTo(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER_STRING, program);
    addShaderTo(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER_STRING, program);

    GLES20.glLinkProgram(program);
    int[] result = new int[] {GLES20.GL_FALSE};
    result[0] = GLES20.GL_FALSE;
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, result, 0);
    abortUnless(result[0] == GLES20.GL_TRUE, GLES20.glGetProgramInfoLog(program));
    GLES20.glUseProgram(program);

    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "y_tex"), 0);
    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "u_tex"), 1);
    GLES20.glUniform1i(GLES20.glGetUniformLocation(program, "v_tex"), 2);

    // Actually set in drawRectangle(), but queried only once here.
    posLocation = GLES20.glGetAttribLocation(program, "in_pos");

    int tcLocation = GLES20.glGetAttribLocation(program, "in_tc");
    GLES20.glEnableVertexAttribArray(tcLocation);
    GLES20.glVertexAttribPointer(tcLocation, 2, GLES20.GL_FLOAT, false, 0, textureCoords);

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    checkNoGLES2Error();
  }
  public void draw(float[] mvpMatrix) {
    // Add program to OpenGL ES 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");

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

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
Example #28
0
  public void draw() {
    // 将program加入OpenGL ES环境中
    GLES20.glUseProgram(mProgram);

    // 获取指向vertex shader的成员vPosition的 handle
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // 启用一个指向三角形的顶点数组的handle
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // 准备三角形的坐标数据
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    // 获取指向fragment shader的成员vColor的handle
    mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // 设置三角形的颜色
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // 画三角形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexCount);

    // 禁用指向三角形的顶点数组
    GLES20.glDisableVertexAttribArray(mPositionHandle);
  }
  @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);
    }
  }
Example #30
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);
  }