Skip to content

Instantly share code, notes, and snippets.

@matthewtoast
Created December 1, 2013 17:31
Show Gist options
  • Save matthewtoast/7737514 to your computer and use it in GitHub Desktop.
Save matthewtoast/7737514 to your computer and use it in GitHub Desktop.
Changes that silence the "Attribute 0 is disabled" warning in WebGL.
diff --git
@@ -1,7 +1,8 @@
var
VERTEX_SHADER_SOURCE = ""+
+ "attribute vec4 a_Position;"+
"void main() {"+
- " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);"+
+ " gl_Position = a_Position;"+
" gl_PointSize = 10.0;"+
"}",
@@ -30,6 +31,19 @@
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
gl.useProgram(shaderProgram);
+// Create a buffer with vertex data:
+var vertices = new Float32Array([0.0, 0.0, 0.0]),
+ vertexBuffer = gl.createBuffer();
+gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
+gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
+
+// Bind position data to attribute 0.
+gl.bindAttribLocation(shaderProgram, 0, 'a_Position');
+
+// Assign pointer.
+gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
+gl.enableVertexAttribArray(0);
+
// Clear the canvas.
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment