Created
September 13, 2012 20:35
-
-
Save philogb/3717435 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
window.addEventListener('DOMContentLoaded', function() { | |
//check support | |
if (!supportsWebGL()) { | |
$('webgl-canvas').innerHTML = 'Your browser doesn\'t seem to support WebGL. More info <a href=\'http://get.webgl.org/\'>here</a>.'; | |
return; | |
} | |
//get context | |
var canvas = $('webgl-canvas'), | |
gl = getWebGLContext(canvas); | |
//create a program | |
createProgramFromURIs(gl, { | |
vsURI: 'shaders/simple.vs', | |
fsURI: 'shaders/simple.fs', | |
onComplete: function(program) { | |
render(program); | |
} | |
}); | |
function render(program) { | |
gl.useProgram(program); | |
var sizeLocation = gl.getUniformLocation(program, 'size'), | |
positionLocation = gl.getAttribLocation(program, 'position'), | |
buffer = gl.createBuffer(), | |
vertices = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1]; | |
//set uniform size data | |
gl.uniform1f(sizeLocation, canvas.width); | |
//set position attribute data | |
gl.bindBuffer(gl.ARRAY_BUFFER, buffer); | |
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); | |
gl.enableVertexAttribArray(positionLocation); | |
gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, false, 0, 0); | |
//draw rectangle | |
gl.drawArrays(gl.TRIANGLES, 0, 6); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wack