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);
  }
  /*
   * Draw function - called for every frame
   */
  public void onDrawFrame(GL10 glUnused) {
    // Ignore the passed-in GL10 interface, and use the GLES20
    // class's static methods instead.
    GLES20.glClearColor(.0f, .0f, .0f, 1.0f);
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glUseProgram(0);
    // the current shader
    Shader shader = _shaders[this._currentShader]; // PROBLEM!
    int program = shader.get_program();

    // Start using the shader
    GLES20.glUseProgram(program);
    checkGlError("glUseProgram");

    setLight(program);
    drawCar(program, new float[] {0.0f, 5.0f, 20.0f});
    drawCar2(program, new float[] {-10.0f, 5.0f, 10.0f});
    drawCar2(program, new float[] {-5.0f, 5.0f, -10.0f});
    drawCar2(program, new float[] {10.0f, 5.0f, 0.0f});
    drawCar2(program, new float[] {50.0f, 5.0f, 15.0f});
    drawRoad(program);

    // eye position
    GLES20.glUniform3fv(
        GLES20.glGetUniformLocation(program, "eyePos") /*shader.eyeHandle*/, 1, eyePos, 0);
  }
  @Override
  public void onDrawFrame(GL10 gl) {
    super.onDrawFrame(gl);
    // GL Draw code onwards
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Do a complete rotation every 10 seconds.
    long time = SystemClock.uptimeMillis() % 10000L;
    float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

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

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

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, getGLSurfaceTexture());
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, glSurfaceTex);
    //        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    //        // Set the active texture unit to texture unit 0.
    //        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    //
    //        // Bind the texture to this unit.
    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, glSurfaceTex);

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

    // Calculate position of the light. Rotate and then push into the distance.
    Matrix.setIdentityM(mLightModelMatrix, 0);
    Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -4.0f);
    Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
    Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);

    Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
    Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.3f);
    Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
    drawCube();

    // Draw a point to indicate the light.
    GLES20.glUseProgram(mPointProgramHandle);
    drawLight();
  }
예제 #4
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);
      }
    }
  }
예제 #5
0
  /**
   * 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);
  }
  @Override
  public void onDrawEye(Eye eye) {
    if (resetCameraFlag) {
      float[] invertedEye = new float[16];
      Matrix.invertM(invertedEye, 0, eye.getEyeView(), 0);
      setUpCamera();
      Matrix.multiplyMM(mCameraMatrix, 0, invertedEye, 0, mCameraMatrix, 0);
      resetCameraFlag = false;
    }
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (lockCameraFlag) {
      mViewMatrix = mCameraMatrix.clone();
    } else {
      Matrix.multiplyMM(mViewMatrix, 0, eye.getEyeView(), 0, mCameraMatrix, 0);
    }

    Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
    Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

    mProjectionMatrix = eye.getPerspective(Z_NEAR, Z_FAR);

    GLES20.glUseProgram(mProgramHandle);
    currentContent.draw(eye);

    if (drawRedPoint) {
      drawTargetingPoint();
    }
    Util.checkGLError("Error Draw Eye");
  }
예제 #7
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);
    }
예제 #8
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);
  }
예제 #9
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);
  }
  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);
  }
예제 #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");
  }
예제 #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);
  }
  @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();
  }
예제 #14
0
  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;
  }
예제 #15
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);
  }
예제 #16
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();
  }
예제 #17
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);
  }
예제 #18
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);
  }
예제 #19
0
  void renderFrame(float fDeltaTime) {
    GLES20.glUseProgram(m_DefaultProgram);

    int posHandle = GLES20.glGetAttribLocation(m_DefaultProgram, "vPosition");
    int uvHandle = GLES20.glGetAttribLocation(m_DefaultProgram, "vUV");
    int textureHandle = GLES20.glGetUniformLocation(m_DefaultProgram, "texture");
    int laserColorHandle = GLES20.glGetUniformLocation(m_DefaultProgram, "colLaser");

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(textureHandle, 0);

    for (GameObject go : gameActivity.gameObjects) {
      go.render(fDeltaTime, posHandle, uvHandle, laserColorHandle);
    }

    GLES20.glDisableVertexAttribArray(posHandle);
    GLES20.glDisableVertexAttribArray(uvHandle);

    ArrayList<PointF> laserSegments = new ArrayList<PointF>();
    ArrayList<Float> laserLengths = new ArrayList<>();
    ArrayList<ColorF> laserColors = new ArrayList<ColorF>();

    gameActivity.computeLasers(laserSegments, laserLengths, laserColors);

    laserRenderer.setLasers(laserSegments, laserLengths, laserColors);
    laserRenderer.render(fDeltaTime);
  }
  @Override
  public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vertexShaderHandle, loadShader(R.raw.vertex_shader));
    GLES20.glCompileShader(vertexShaderHandle);
    int fragmentShaderHandle = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fragmentShaderHandle, loadShader(R.raw.fragment_shader));
    GLES20.glCompileShader(fragmentShaderHandle);
    int programHandle = GLES20.glCreateProgram();
    GLES20.glAttachShader(programHandle, vertexShaderHandle);
    GLES20.glAttachShader(programHandle, fragmentShaderHandle);
    GLES20.glLinkProgram(programHandle);
    GLES20.glUseProgram(programHandle);
    Object3D.init(programHandle);
    mLightPosHandle = GLES20.glGetUniformLocation(programHandle, "uLightPos");

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glCullFace(GLES20.GL_BACK);

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

    mPrism.init();
    mCylinder.init();
    mSphere.init();
  }
예제 #21
0
  /**
   * OnDrawFrame is called whenever a new frame needs to be drawn. Normally, this is done at the
   * refresh rate of the screen.
   */
  @Override
  public void onDrawFrame(GL10 glUnused) {
    // Clear the rendering surface.
    glClear(GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    long time = SystemClock.uptimeMillis() % 10000L;
    float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

    glUseProgram(program);

    // Assign the matrix

    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, -4.0f, 0.0f, -7.0f);
    Matrix.scaleM(modelMatrix, 0, 0.5f, 2.0f, 2.0f);
    drawCube();
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -7.0f);
    Matrix.rotateM(modelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
    drawCube();
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 4.0f, 0.0f, -7.0f);
    Matrix.scaleM(modelMatrix, 0, 0.5f, 2.0f, 2.0f);
    drawCube();
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -9.0f);
    Matrix.scaleM(modelMatrix, 0, 4.0f, 2.0f, 0.5f);
    drawCube();
  }
  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);
  }
예제 #23
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);
  }
예제 #24
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);
  }
예제 #25
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);
  }
예제 #26
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);
    }
  }
예제 #27
0
파일: Points.java 프로젝트: LuanSala/Viewer
  public void draw(boolean mvpModified, float[] mvpMatrix) {
    GLES20.glUseProgram(mProgram);
    if (mvpModified) GLES20.glUniformMatrix4fv(mMVPMatrix, 1, false, mvpMatrix, 0);

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, VBO[0]);
    GLES20.glEnableVertexAttribArray(mPosition);
    GLES20.glEnableVertexAttribArray(mColor);
    if (problemBufferInterleaved) {
      GLES20.glVertexAttribPointer(mPosition, 3, GLES20.GL_FLOAT, false, 0, 0);
      GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, VBO[1]);
      GLES20.glVertexAttribPointer(mColor, 3, GLES20.GL_UNSIGNED_BYTE, true, 0, 0);
    } else {
      // Descobri que da erro no DrawArrays por causa de alguma
      // coisa que ocorre aqui no VertexAttribPointer. Não reconhece o stride '15', e tambem
      // nao reconhece stride que nao e multiplo de 4.
      if (mPointCloudWithColor) {
        GLES20.glVertexAttribPointer(mPosition, 3, GLES20.GL_FLOAT, false, 15, 0);
        GLES20.glVertexAttribPointer(mColor, 3, GLES20.GL_UNSIGNED_BYTE, true, 15, 12);
      } else {
        GLES20.glDisableVertexAttribArray(mColor);
        // Nao ha cor no arquivo escolhido, consequentemente, o buffer dos vertices
        // sao diretos. Ha apenas 1 buffer para vertices. Nao ha "stride" no buffer.
        GLES20.glVertexAttribPointer(mPosition, 3, GLES20.GL_FLOAT, false, 0, 0);
        // GLES20.glVertexAttribPointer(mColor, 3, GLES20.GL_UNSIGNED_BYTE, true, 0, 0);
        GLES20.glVertexAttrib3f(mColor, mRGB[0], mRGB[1], mRGB[2]);
      }
    }
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, totalPoints);
    if (!problemBufferInterleaved && GLES20.glGetError() == GLES20.GL_INVALID_OPERATION) {
      // Log.d(TAG,"Problem in buffer");
      problemBufferInterleaved = true;
      separateBuffers();
      loadVBO2();
      draw(mvpModified, mvpMatrix);
    }
    GLES20.glDisableVertexAttribArray(mPosition);
    GLES20.glDisableVertexAttribArray(mColor);
    GLES20.glUseProgram(0);

    GLES20.glFlush();
  }
예제 #28
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();
    }
    @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);
    }
예제 #30
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); // 绘制星星点
 }