0

Possible Duplicate:
Is Google’s Android OpenGL tutorial teaching incorrect linear algebra?

Learning OpenGL ES 2.0 on Android. Using Emulator, running Android 4.1.

Copied and pasted snippets from Android Developer Site / OpenGL

Updated onDrawFrame method. Pasted below. Added Matrix.setIdentityM(mRotationMatrix, 0) since it's was a Null Matrix. Changed mAngle to angle (line 16).

public void onDrawFrame(GL10 unused) {
    // Redraw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // Create a rotation transformation for the triangle
    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    Matrix.setIdentityM(mRotationMatrix, 0); //added
    Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, 1.0f); //changed

    // Combine the rotation matrix with the projection and camera view
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

    // Draw shape
    mTriangle.draw(mMVPMatrix);
}

And Commented out setRenderMode(RENDERMODE_WHEN_DIRTY);

Yet the Triangle drawn did not rotated. Where did I go wrong?

Community
  • 1
  • 1
ShouravBR
  • 685
  • 7
  • 10
  • 1
    Please see the example code from Ian's answer to [this question](http://stackoverflow.com/questions/11925647/is-googles-android-opengl-tutorial-teaching-incorrect-linear-algebra). The google OpenGL tutorial is broken and confusing. – Tim Oct 01 '12 at 18:22

1 Answers1

0

Thanks to this question here. I learnt to solve this.

Just edit the Vertex Shader Code. uMVPMatrix is important without this the projection is not applied.

private final String vertexShaderCode = "attribute vec4 vPosition;"
        +"uniform mat4 uMVPMatrix;"
        + "void main() {" + "  gl_Position = uMVPMatrix * vPosition;" + "}";
Community
  • 1
  • 1
ShouravBR
  • 685
  • 7
  • 10