Skip to content

Instantly share code, notes, and snippets.

@jcserracampos
Last active April 2, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcserracampos/cdb8884a7705fcaad155d89afe5a9e10 to your computer and use it in GitHub Desktop.
Save jcserracampos/cdb8884a7705fcaad155d89afe5a9e10 to your computer and use it in GitHub Desktop.
Contexto WebGL
<!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