Last active
April 2, 2018 22:54
-
-
Save jcserracampos/cdb8884a7705fcaad155d89afe5a9e10 to your computer and use it in GitHub Desktop.
Contexto 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
<!DOCTYPE html> | |
<html> | |
<header> | |
<meta charset="UTF-8" /> | |
<title>Criação de um contexto WebGL</title> | |
</header> | |
<body> | |
<h2 id="info-id">WebGL não suportado</h2> | |
<canvas id="canvas-id" style="border:1px solid black" width="500" weigth="500"> | |
O seu browser não suporta o elemento canvas | |
</canvas> | |
<script> | |
// Firefox não consegue detectar um canvas criado via HTML | |
if( navigator.userAgent.toLowerCase().indexOf('firefox') > -1 ){ | |
var canvas = document.createElement('canvas'); | |
canvas.setAttribute('id', 'canvas-id'); | |
canvas.setAttribute('width', '500'); | |
canvas.setAttribute('height', '500'); | |
document.getElementById('canvas-id').appendChild(canvas); | |
} | |
var info = document.getElementById("info-id"); | |
var canvas = document.getElementById("canvas-id"); | |
var gl = canvas.getContext("webgl2"); | |
if(gl) { | |
info.innerHTML = "Browser suporta WebGL2"; | |
} else { | |
gl = canvas.getContext("webgl"); | |
if(gl) { | |
info.innerHTML = "Browser suporta WebGL1"; | |
} | |
} | |
gl.clearColor(0.3, 0.3, 0.3, 1); | |
gl.clear(gl.COLOR_BUFFER_BIT); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment