Skip to content

Commit 5e4bda6

Browse files
committed
updated to api 33.
but can't use the 3.0 es. 3.1 works, I don't know why.
1 parent 622718b commit 5e4bda6

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

HelloOpenGLES30/.idea/gradle.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HelloOpenGLES30/app/src/main/java/com/example/android/opengl30/Square.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,32 @@
2323
import android.opengl.GLES30;
2424

2525
/**
26-
* A two-dimensional square for use as a drawn object in OpenGL ES 2.0.
26+
* A two-dimensional square for use as a drawn object in OpenGL ES 3.1.
27+
* I actually can get 3.0 to work. confusing.
2728
*/
2829
public class Square {
2930

3031
private final String vertexShaderCode =
3132
// This matrix member variable provides a hook to manipulate
3233
// the coordinates of the objects that use this vertex shader
33-
"uniform mat4 uMVPMatrix;" +
34-
"attribute vec4 vPosition;" +
35-
"void main() {" +
34+
"#version 310 es\n"+
35+
"uniform mat4 uMVPMatrix;\n" +
36+
"in vec4 vPosition;\n" +
37+
"void main() {\n" +
3638
// The matrix must be included as a modifier of gl_Position.
3739
// Note that the uMVPMatrix factor *must be first* in order
3840
// for the matrix multiplication product to be correct.
39-
" gl_Position = uMVPMatrix * vPosition;" +
40-
"}";
41+
" gl_Position = uMVPMatrix * vPosition;\n" +
42+
"}\n";
4143

4244
private final String fragmentShaderCode =
43-
"precision mediump float;" +
44-
"uniform vec4 vColor;" +
45-
"void main() {" +
46-
" gl_FragColor = vColor;" +
47-
"}";
45+
"#version 310 es \n"+
46+
"precision mediump float; \n" +
47+
"in uniform vec4 vColor;\n" +
48+
"out vec4 gl_FragColor;\n" +
49+
"void main() {\n" +
50+
" gl_FragColor = vColor;\n" +
51+
"}\n";
4852

4953
private final FloatBuffer vertexBuffer;
5054
private final ShortBuffer drawListBuffer;

HelloOpenGLES30/app/src/main/java/com/example/android/opengl30/Triangle.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,33 @@
2222
import android.opengl.GLES30;
2323

2424
/**
25-
* A two-dimensional triangle for use as a drawn object in OpenGL ES 2.0.
25+
* A two-dimensional triangle for use as a drawn object in OpenGL ES 3.1
26+
*
27+
* actually fails with the 300. I do not have a clue what it doesn't work.
2628
*/
2729
public class Triangle {
2830

2931
private final String vertexShaderCode =
30-
// This matrix member variable provides a hook to manipulate
31-
// the coordinates of the objects that use this vertex shader
32-
"uniform mat4 uMVPMatrix;" +
33-
"attribute vec4 vPosition;" +
34-
"void main() {" +
32+
// This matrix member variable provides a hook to manipulate
33+
// the coordinates of the objects that use this vertex shader
34+
"#version 310 es\n"+
35+
"uniform mat4 uMVPMatrix;\n" +
36+
"in vec4 vPosition;\n" +
37+
"void main() {\n" +
3538
// the matrix must be included as a modifier of gl_Position
3639
// Note that the uMVPMatrix factor *must be first* in order
3740
// for the matrix multiplication product to be correct.
38-
" gl_Position = uMVPMatrix * vPosition;" +
39-
"}";
41+
" gl_Position = uMVPMatrix * vPosition;\n" +
42+
"}\n";
4043

4144
private final String fragmentShaderCode =
42-
"precision mediump float;" +
43-
"uniform vec4 vColor;" +
44-
"void main() {" +
45-
" gl_FragColor = vColor;" +
46-
"}";
45+
"#version 310 es \n"+
46+
"precision mediump float; \n" +
47+
"in uniform vec4 vColor;\n" +
48+
"out vec4 gl_FragColor;\n" +
49+
"void main() {\n" +
50+
" gl_FragColor = vColor;\n" +
51+
"}\n";
4752

4853
private final FloatBuffer vertexBuffer;
4954
private final int mProgram;
@@ -54,24 +59,24 @@ public class Triangle {
5459
// number of coordinates per vertex in this array
5560
static final int COORDS_PER_VERTEX = 3;
5661
static float triangleCoords[] = {
57-
// in counterclockwise order:
58-
0.0f, 0.622008459f, 0.0f, // top
59-
-0.5f, -0.311004243f, 0.0f, // bottom left
60-
0.5f, -0.311004243f, 0.0f // bottom right
62+
// in counterclockwise order:
63+
0.0f, 0.622008459f, 0.0f, // top
64+
-0.5f, -0.311004243f, 0.0f, // bottom left
65+
0.5f, -0.311004243f, 0.0f // bottom right
6166
};
6267
private final int vertexCount = triangleCoords.length / COORDS_PER_VERTEX;
6368
private final int vertexStride = COORDS_PER_VERTEX * 4; // 4 bytes per vertex
6469

65-
float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 0.0f };
70+
float color[] = {0.63671875f, 0.76953125f, 0.22265625f, 0.0f};
6671

6772
/**
6873
* Sets up the drawing object data for use in an OpenGL ES context.
6974
*/
7075
public Triangle() {
7176
// initialize vertex byte buffer for shape coordinates
7277
ByteBuffer bb = ByteBuffer.allocateDirect(
73-
// (number of coordinate values * 4 bytes per float)
74-
triangleCoords.length * 4);
78+
// (number of coordinate values * 4 bytes per float)
79+
triangleCoords.length * 4);
7580
// use the device hardware's native byte order
7681
bb.order(ByteOrder.nativeOrder());
7782

@@ -84,9 +89,9 @@ public Triangle() {
8489

8590
// prepare shaders and OpenGL program
8691
int vertexShader = MyGLRenderer.loadShader(
87-
GLES30.GL_VERTEX_SHADER, vertexShaderCode);
92+
GLES30.GL_VERTEX_SHADER, vertexShaderCode);
8893
int fragmentShader = MyGLRenderer.loadShader(
89-
GLES30.GL_FRAGMENT_SHADER, fragmentShaderCode);
94+
GLES30.GL_FRAGMENT_SHADER, fragmentShaderCode);
9095

9196
mProgram = GLES30.glCreateProgram(); // create empty OpenGL Program
9297
GLES30.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
@@ -99,7 +104,7 @@ public Triangle() {
99104
* Encapsulates the OpenGL ES instructions for drawing this shape.
100105
*
101106
* @param mvpMatrix - The Model View Project matrix in which to draw
102-
* this shape.
107+
* this shape.
103108
*/
104109
public void draw(float[] mvpMatrix) {
105110
// Add program to OpenGL environment
@@ -113,9 +118,9 @@ public void draw(float[] mvpMatrix) {
113118

114119
// Prepare the triangle coordinate data
115120
GLES30.glVertexAttribPointer(
116-
mPositionHandle, COORDS_PER_VERTEX,
117-
GLES30.GL_FLOAT, false,
118-
vertexStride, vertexBuffer);
121+
mPositionHandle, COORDS_PER_VERTEX,
122+
GLES30.GL_FLOAT, false,
123+
vertexStride, vertexBuffer);
119124

120125
// get handle to fragment shader's vColor member
121126
mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor");

0 commit comments

Comments
 (0)