0

I only use the matrix to draw a square! Only the matrix is updated in each rendering. How to remove Vertex Position from my codes

lock like this https://webgl2fundamentals.org/webgl/lessons/webgl-drawing-without-data.html

#version 300 es
in vec4 a_position;
in vec2 a_texcoord;
uniform mat4 u_matrix;
out vec2 v_texcoord;
void main() 
    ngl_Position = u_matrix * a_position;
    v_texcoord = a_texcoord;
}

and remove this

gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
0, 0, 0,
0, 1, 0,
1, 0, 0,
0, 1, 0,
1, 1, 0,
1, 0, 0]), gl.STATIC_DRAW);

Sorry for using Google Translator

1 Answers1

0

Here is your square vertex shader. You don't need to use a matrix.

#version 300 es

void main() {
  float xs[6] = float[](0.0, 0.0, 1.0, 0.0, 1.0, 1.0);
  float ys[6] = float[](0.0, 1.0, 0.0, 1.0, 1.0, 0.0);
  float x = xs[gl_VertexID];
  float y = ys[gl_VertexID];
  gl_Position = vec4(x, y, 0, 1);
}

And to render you just do this. You don't need to do any bufferData or any uniforms.

gl.drawArrays(gl.TRIANGLES, 0, 6);
Curtis
  • 2,486
  • 5
  • 40
  • 44