You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

4 years ago
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var gl; // Un variable global para el contexto WebGL
  5. function start() {
  6. var canvas = document.getElementById("glcanvas");
  7. gl = initWebGL(canvas); // Inicializar el contexto GL
  8. // Solo continuar si WebGL esta disponible y trabajando
  9. if (gl) {
  10. gl.clearColor(0.0, 0.0, 0.0, 1.0); // Establecer el color base en negro, totalmente opaco
  11. gl.enable(gl.DEPTH_TEST); // Habilitar prueba de profundidad
  12. gl.depthFunc(gl.LEQUAL); // Objetos cercanos opacan objetos lejanos
  13. gl.clear(gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT); // Limpiar el buffer de color asi como el de profundidad
  14. }
  15. }
  16. function initWebGL(canvas) {
  17. gl = null;
  18. try {
  19. // Tratar de tomar el contexto estandar. Si falla, retornar al experimental.
  20. gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
  21. }
  22. catch(e) {}
  23. // Si no tenemos ningun contexto GL, date por vencido ahora
  24. if (!gl) {
  25. alert("Imposible inicializar WebGL. Tu navegador puede no soportarlo.");
  26. gl = null;
  27. }
  28. return gl;
  29. }
  30. </script>
  31. </head>
  32. <body onload="start()">
  33. <canvas id="glcanvas" width="640" height="480">
  34. Tu navegador parece no soportar el elemento HTML5 <code>&lt;canvas&gt;</code>.
  35. </canvas>
  36. </body>
  37. </html>