티스토리 뷰
OpenGL ES 2.0 Practice 2 : Simple Matrix
Simple Triangle 에서 shader 코드에 matrix 연산을 추가하여 Triangle 을 회전하는 코드 입니다.
기본 shader 코드에서 matrix 연산을 추가합니다.
// no matrix transform
"precision mediump float;\n" +
"attribute vec3 aPosition;\n" +
"void main() {\n" +
" gl_Position = vec4(aPosition, 1.0);\n" +
"}\n",
// matrix transform
"precision mediump float;\n" +
"attribute vec3 aPosition;\n" +
"uniform mat4 uMatrix;\n" +
"void main() {\n" +
" gl_Position = uMatrix * vec4(aPosition, 1.0);\n" +
"}\n",
그리고, 4x4 matrix 처리를 위해 float mMatrix[] = new float[16]; 를 멤버 변수로 추가합니다.
// 4x4 matrix
private float mMatrix[] = new float[16];
앱 시작 시, 이 matrix 값을 identity matrix로 초기화 하고, 매 frame마다 rotation 값을 연산하도록 합니다.
public SimpleMatrix() {
...
// init matrix value
Matrix.setIdentityM(mMatrix, 0);
}
@Override
public void draw() {
...
// triangle matrix
// z-axis, 1 degree rotation every frames
Matrix.rotateM(mMatrix, 0, 1.0f, 0.0f, 0.0f, 1.0f);
GLES20.glUniformMatrix4fv(GLES20.glGetUniformLocation(mProgram, "uMatrix"), 1, false, mMatrix, 0);
...
}
결과 화면 ... (Nexus 7 2nd, Android 6.0)
'Programming > OpenGL ES' 카테고리의 다른 글
OpenGL ES 2.0 Practice 5 : Simple Texture (0) | 2016.10.23 |
---|---|
OpenGL ES 2.0 Practice 4 : Simple Light (0) | 2016.10.20 |
OpenGL ES 2.0 Practice 3 : Simple Projection (0) | 2016.10.09 |
OpenGL ES 2.0 Practice 1 : Simple Triangle (0) | 2016.10.08 |
- Total
- Today
- Yesterday
- 토크
- OpenGL
- practices
- process
- 툴
- Android
- 실전
- smapler2D
- 프랙티스
- talk
- OpenGL ES
- 스크럼
- OPENGLES
- XP
- 애자일
- triangle
- aglie
- 프로세스
- projection
- light
- texture
- Scrum
- OpenGL ES 2.0
- TOOL
- Matrix
- Practice
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |