doc_webgl-bindings.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <!-- Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ -->
  3. <!doctype html>
  4. <html>
  5. <head>
  6. <meta charset="utf-8"/>
  7. <title>WebGL editor test page</title>
  8. </head>
  9. <body>
  10. <canvas id="canvas" width="1024" height="1024"></canvas>
  11. <script type="text/javascript;version=1.8">
  12. "use strict";
  13. let canvas, gl;
  14. let customFramebuffer;
  15. let customRenderbuffer;
  16. let customTexture;
  17. window.onload = function() {
  18. canvas = document.querySelector("canvas");
  19. gl = canvas.getContext("webgl", { preserveDrawingBuffer: true });
  20. gl.clearColor(1.0, 0.0, 0.0, 1.0);
  21. gl.clear(gl.COLOR_BUFFER_BIT);
  22. customFramebuffer = gl.createFramebuffer();
  23. gl.bindFramebuffer(gl.FRAMEBUFFER, customFramebuffer);
  24. customRenderbuffer = gl.createRenderbuffer();
  25. gl.bindRenderbuffer(gl.RENDERBUFFER, customRenderbuffer);
  26. gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 1024, 1024);
  27. customTexture = gl.createTexture();
  28. gl.bindTexture(gl.TEXTURE_2D, customTexture);
  29. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  30. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  31. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  32. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  33. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1024, 1024, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
  34. gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, customTexture, 0);
  35. gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, customRenderbuffer);
  36. gl.viewport(128, 256, 384, 512);
  37. gl.clearColor(0.0, 1.0, 0.0, 1.0);
  38. gl.clear(gl.COLOR_BUFFER_BIT);
  39. drawScene();
  40. }
  41. function drawScene() {
  42. gl.clearColor(0.0, 0.0, 1.0, 1.0);
  43. gl.clear(gl.COLOR_BUFFER_BIT);
  44. window.requestAnimationFrame(drawScene);
  45. }
  46. </script>
  47. </body>
  48. </html>