Last active
August 29, 2015 14:22
-
-
Save mathdoodle/2e684eed43835f280439 to your computer and use it in GitHub Desktop.
WebGL 001 canvas
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
{ | |
"uuid": "8f482ee9-5870-4c78-b6e0-54e46563beab", | |
"description": "WebGL 001 canvas", | |
"dependencies": { | |
"DomReady": "latest" | |
} | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<style> | |
/* STYLE-MARKER */ | |
</style> | |
<!-- SCRIPTS-MARKER --> | |
<script> | |
// CODE-MARKER | |
</script> | |
</head> | |
<body> | |
<canvas id='my-canvas' width='400' height='300'></canvas> | |
</body> | |
</html> |
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
DomReady.ready(main); | |
function main() { | |
var canvas = <HTMLCanvasElement>document.getElementById('my-canvas'); | |
var gl = initWebGL(canvas); | |
gl.clearColor(1.0, 0.0, 0.0, 1.0); | |
gl.clear(gl.COLOR_BUFFER_BIT); | |
} | |
function initWebGL(canvas: HTMLCanvasElement): WebGLRenderingContext { | |
var context: WebGLRenderingContext = null; | |
try { | |
// Try to grab the standard context. If it fails, fallback to experimental. | |
context = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); | |
} | |
catch(e) { | |
} | |
if (context) { | |
return context; | |
} | |
else { | |
throw new Error("Unable to initialize WebGL. Your browser may not support it."); | |
} | |
} |
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
body { background-color: grey; } | |
canvas { background-color: white;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment