コード例 #1
0
  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);
  }
コード例 #2
0
ファイル: Ball.java プロジェクト: kivechang/openGl20Games
  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);
  }
コード例 #3
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");
  }
コード例 #4
0
  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);
  }
コード例 #5
0
ファイル: GLDrawer2D.java プロジェクト: CGmaybe10/UVCCamera
  /** 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);
  }
コード例 #6
0
ファイル: Scene.java プロジェクト: Karm/galgs
  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);
      }
    }
  }
コード例 #7
0
ファイル: GLSprite.java プロジェクト: ryanbis/AltBridge
  @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
  /** 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);
  }
コード例 #9
0
    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();
    }
コード例 #10
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);
  }
コード例 #11
0
  public void draw() {
    GLES20.glUseProgram(shaderProgram);

    int muMVPMat = GLES20.glGetUniformLocation(shaderProgram, "uMVPMatrix");
    GLESUtils.checkGlError("glGetUniformLocation");
    GLES20.glUniformMatrix4fv(muMVPMat, 1, false, scene.modelViewProjectionMatrix(), 0);
    GLESUtils.checkGlError("glUniformMatrix4fv");

    int mPositionH = vertexAttribArrayf("vPosition", CpV, cStride, posBuffer);
    GLESUtils.checkGlError("vPosition");

    int normalH = vertexAttribArrayf("vNormal", CpV, cStride, normalBuffer);
    GLESUtils.checkGlError("vNormal");

    int mColorH = GLES20.glGetAttribLocation(shaderProgram, "vColor");
    GLES20.glVertexAttrib4f(mColorH, c[0], c[1], c[2], c[3]);
    GLESUtils.checkGlError("vColor");

    int phaseH = vertexAttribArrayf("vPhase", 1, NumVerts, phaseBuffer);
    GLESUtils.checkGlError("vPhase");

    int gTime = GLES20.glGetUniformLocation(shaderProgram, "iGlobalTime");
    GLES20.glUniform1f(gTime, (float) (SystemClock.uptimeMillis() / 1000.0));
    GLESUtils.checkGlError("iGlobalTime");

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, oBufferLength);

    GLES20.glDisableVertexAttribArray(mPositionH);
    GLES20.glDisableVertexAttribArray(normalH);
    GLES20.glDisableVertexAttribArray(mColorH);
    GLES20.glDisableVertexAttribArray(phaseH);
  }
コード例 #12
0
    @Override
    public void applyParams() {
      super.applyParams();

      createLightViewProjectionMatrix(mLight).toFloatArray(mLightMatrix);
      GLES20.glUniformMatrix4fv(muLightMatrixHandle, 1, false, mLightMatrix, 0);
    }
コード例 #13
0
  /**
   * 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));
  }
コード例 #14
0
    public void draw(float[] viewProjMatrix) {
        glUseProgram(mProgram);

        multiplyMM(mMVPMatrix, 0, viewProjMatrix, 0, mModelMatrix, 0);
        int handle = glGetUniformLocation(mProgram, Constants.U_MVP_MATRIX);
        glUniformMatrix4fv(handle, 1, false, mMVPMatrix, 0);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, mTextureA);
        handle = glGetUniformLocation(mProgram, Constants.U_TEX_UNIT_0);
        glUniform1i(handle, 0);

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, mTextureB);
        handle = glGetUniformLocation(mProgram, Constants.U_TEX_UNIT_1);
        glUniform1i(handle, 1);

        handle = glGetUniformLocation(mProgram, Constants.U_MIX_FACTOR);
        glUniform1f(handle, calcMixFactor());

        handle = glGetUniformLocation(mProgram, Constants.U_BACK_COLOR);
        glUniform3fv(handle, 1, mBackColor, 0);

        mMesh.draw(mProgram);
    }
コード例 #15
0
  @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);
  }
コード例 #16
0
  @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);
    }
  }
コード例 #17
0
  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);
  }
コード例 #18
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);
  }
コード例 #19
0
ファイル: TopPart1.java プロジェクト: kivechang/openGl20Games
  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);
  }
コード例 #20
0
ファイル: ObjectRenderer.java プロジェクト: vingt-2/Sweep2D
  public boolean Draw(Matrix4 projectionMatrix, Matrix4 viewMatrix) {
    GLES20.glUseProgram(programID);

    Matrix4 mvp =
        Matrix4.Multiply(
            projectionMatrix, Matrix4.Multiply(viewMatrix, parent.transform.transformMatrix));

    float[] mvpArray = mvp.GetOneDimensionalArray();

    GLES20.glUniformMatrix4fv(mvpLocation, 1, false, mvpArray, 0);

    GLES20.glUniform1f(opacityLocation, opacity);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID);

    GLES20.glUniform1i(textureSamplerLocation, 0);

    // Log.i(DEBUG_TAG,"Enabling " + vertexArrayList.size() + " attribs");

    for (GLVertexArrayObject element : vertexArrayList) {
      GLES20.glEnableVertexAttribArray(element.attributeNumber);
    }

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

    for (GLVertexArrayObject element : vertexArrayList) {
      GLES20.glDisableVertexAttribArray(element.attributeNumber);
    }
    return true;
  }
コード例 #21
0
  public void drawSelf(
      int ballTexId, int isShadow, int planeId, int isLanbanYy) // 0-no shadow 1-with shadow
      {
    // 制定使用某套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(maLightLocationHandle, 1, MatrixState.lightPositionFB);
    // 将摄像机位置传入shader程序
    GLES20.glUniform3fv(maCameraHandle, 1, MatrixState.cameraFB);
    // 将是否绘制阴影属性传入shader程序
    GLES20.glUniform1i(muIsShadow, isShadow);
    GLES20.glUniform1i(muIsShadowFrag, isShadow);
    GLES20.glUniform1i(muIsLanBanShdow, isLanbanYy);
    // 将摄像机矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muCameraMatrixHandle, 1, false, MatrixState.mVMatrix, 0);
    // 将投影矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muProjMatrixHandle, 1, false, MatrixState.mProjMatrix, 0);
    // 将平面位置传入程序
    GLES20.glUniform3fv(muPlaneV, 1, Constant.mianFXL[planeId][0]);
    // 将平面法向量传入程序
    GLES20.glUniform3fv(muPlaneN, 1, Constant.mianFXL[planeId][1]);

    // 传入顶点位置数据
    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, 3, 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, ballTexId);
    GLES20.glUniform1i(muBallTexHandle, 0);
    // 绘制纹理矩形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
  }
コード例 #22
0
  @Override
  public void onDrawFrame(GL10 unused) {
    GLES20.glClearColor(0f, 0f, 0f, 1f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

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

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

    long time = SystemClock.uptimeMillis();

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

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

    mShaderStar.useProgram();

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

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

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

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

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

    GLES20.glDisable(GLES20.GL_BLEND);
  }
コード例 #23
0
ファイル: GLDrawer2D.java プロジェクト: CGmaybe10/UVCCamera
  /**
   * draw specific texture with specific texture matrix
   *
   * @param tex_id texture ID
   * @param tex_matrix texture matrix、if this is null, the last one use(we don't check size of this
   *     array and needs at least 16 of float)
   */
  public void draw(final int tex_id, final float[] tex_matrix) {
    GLES20.glUseProgram(hProgram);
    if (tex_matrix != null) GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, tex_matrix, 0);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex_id);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, VERTEX_NUM);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
    GLES20.glUseProgram(0);
  }
コード例 #24
0
 public void drawSelf() {
   GLES20.glUseProgram(mProgram); // 制定使用某套着色器程序
   // 将最终变换矩阵传入着色器程序
   GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
   GLES20.glUniform1f(uPointSizeHandle, scale); // 将顶点尺寸传入着色器程序
   GLES20.glVertexAttribPointer( // 为画笔指定顶点位置数据
       maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer);
   // 允许顶点位置数据数组
   GLES20.glEnableVertexAttribArray(maPositionHandle);
   GLES20.glDrawArrays(GLES20.GL_POINTS, 0, vCount); // 绘制星星点
 }
コード例 #25
0
ファイル: NativeGL2_Android.java プロジェクト: RMMJR/g3m
 @Override
 public void uniformMatrix4fv(
     final IGLUniformID location, final boolean transpose, final MutableMatrix44D matrix) {
   checkOpenGLThread();
   GLES20.glUniformMatrix4fv( //
       ((GLUniformID_Android) location).getID(), //
       1, //
       transpose, //
       matrix.getColumnMajorFloatArray(), //
       0 //
       );
 }
コード例 #26
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);
  }
コード例 #27
0
ファイル: Stick.java プロジェクト: kivechang/openGl20Games
  public void drawSelf(float angle, float x, float y, float z) {
    // 制定使用某套shader程序
    MatrixState.pushMatrix();
    MySurfaceView.init = false;
    Transform trans = body.getMotionState().getWorldTransform(new Transform());
    MatrixState.translate(trans.origin.x, trans.origin.y, trans.origin.z);
    Quat4f ro = trans.getRotation(new Quat4f());
    if (ro.x != 0 || ro.y != 0 || ro.z != 0) {
      float[] fa = SYSUtil.fromSYStoAXYZ(ro);
      if (isNumber(fa[0] + "") && isNumber(fa[1] + "") && isNumber(fa[2] + "")) {

        MatrixState.rotate(fa[0], fa[1], fa[2], fa[3]);
      }
    }

    GLES20.glUseProgram(mProgram);
    MatrixState.rotate(angle, x, y, z);
    // 将最终变换矩阵传入shader程序
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, MatrixState.getFinalMatrix(), 0);
    // 将位置、旋转变换矩阵传入着色器程序
    GLES20.glUniformMatrix4fv(muMMatrixHandle, 1, false, MatrixState.currMatrix, 0);
    // 将光源位置传入着色器程序
    GLES20.glUniform3fv(maLightLocationHandle, 1, MatrixState.lightPositionFBRed);
    // 将摄像机位置传入着色器程序
    GLES20.glUniform3fv(maCameraHandle, 1, MatrixState.cameraFB);

    // 为画笔指定顶点位置数据
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4, mVertexBuffer);
    // 为画笔指定顶点法向量数据
    GLES20.glVertexAttribPointer(maNormalHandle, 4, GLES20.GL_FLOAT, false, 3 * 4, mNormalBuffer);
    // 允许顶点位置数据数组
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    GLES20.glEnableVertexAttribArray(maNormalHandle);

    // 绘制三角形
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
    MatrixState.popMatrix();
  }
コード例 #28
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);
    }
  }
コード例 #29
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);
  }
コード例 #30
0
ファイル: glObjects.java プロジェクト: ravibrk/touchCAD
    public void draw(float[] mvpMatrix) {
      GLES20.glUseProgram(mProgram);
      mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
      GLES20.glEnableVertexAttribArray(mPositionHandle);
      GLES20.glVertexAttribPointer(
          mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

      mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");
      GLES20.glUniform4fv(mColorHandle, 1, color, 0);
      mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
      checkGlError("glGetUniformLocation");
      GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
      checkGlError("glUniformMatrix4fv");
      GLES20.glDrawArrays(GLES20.GL_LINES, 0, vertexCount);
      GLES20.glDisableVertexAttribArray(mPositionHandle);
    }