From 738afcb259cfd8e3e8654898049c8dc01ef2193e Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Thu, 22 Sep 2022 20:46:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9git=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MyOpenGLLearn/.gitignore | 1 - MyOpenGLLearn/app/src/main/assets/frag.glsl | 6 ++++++ MyOpenGLLearn/app/src/main/assets/vertex.glsl | 10 ++++++++++ .../main/java/com/navinfo/myopengllearn/Triangle.java | 8 ++++---- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 MyOpenGLLearn/app/src/main/assets/frag.glsl create mode 100644 MyOpenGLLearn/app/src/main/assets/vertex.glsl diff --git a/MyOpenGLLearn/.gitignore b/MyOpenGLLearn/.gitignore index 3021787..9836993 100644 --- a/MyOpenGLLearn/.gitignore +++ b/MyOpenGLLearn/.gitignore @@ -14,4 +14,3 @@ .externalNativeBuild .cxx local.properties -/app/ diff --git a/MyOpenGLLearn/app/src/main/assets/frag.glsl b/MyOpenGLLearn/app/src/main/assets/frag.glsl new file mode 100644 index 0000000..9f9054d --- /dev/null +++ b/MyOpenGLLearn/app/src/main/assets/frag.glsl @@ -0,0 +1,6 @@ +precision mediump float; +varying vec4 vColor; //接收从顶点着色器过来的参数 +void main() +{ + gl_FragColor = vColor;//给此片元颜色值 +} \ No newline at end of file diff --git a/MyOpenGLLearn/app/src/main/assets/vertex.glsl b/MyOpenGLLearn/app/src/main/assets/vertex.glsl new file mode 100644 index 0000000..334b72b --- /dev/null +++ b/MyOpenGLLearn/app/src/main/assets/vertex.glsl @@ -0,0 +1,10 @@ +uniform mat4 uMVPMatrix; //总变换矩阵 +attribute vec3 aPosition; //顶点位置 +attribute vec4 aColor; //顶点颜色 +varying vec4 vColor; //用于传递给片元着色器的变量 + +void main() +{ + gl_Position = uMVPMatrix * vec4(aPosition,1); //根据总变换矩阵计算此次绘制此顶点位置 + vColor = aColor;//将接收的颜色传递给片元着色器 +} \ No newline at end of file diff --git a/MyOpenGLLearn/app/src/main/java/com/navinfo/myopengllearn/Triangle.java b/MyOpenGLLearn/app/src/main/java/com/navinfo/myopengllearn/Triangle.java index 09bd1b9..9bdcc76 100644 --- a/MyOpenGLLearn/app/src/main/java/com/navinfo/myopengllearn/Triangle.java +++ b/MyOpenGLLearn/app/src/main/java/com/navinfo/myopengllearn/Triangle.java @@ -40,9 +40,9 @@ public class Triangle final float UNIT_SIZE=0.2f; float vertices[]=new float[] { - -4*UNIT_SIZE,0, - 0,0,-4*UNIT_SIZE, - 0,4*UNIT_SIZE,0,0 + -4*UNIT_SIZE,0, 0, + 0,-4*UNIT_SIZE, 0, + 4*UNIT_SIZE,0,0 }; ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); @@ -55,7 +55,7 @@ public class Triangle { 1,1,1,0, 0,0,1,0, - 0,1,0,0 + 0,1,0,0, }; ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);