Created
December 1, 2013 17:31
-
-
Save matthewtoast/7737514 to your computer and use it in GitHub Desktop.
Changes that silence the "Attribute 0 is disabled" warning in WebGL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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