shadertoy-prep.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!-- Licensed under a BSD license. See license.html for license -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
  7. <title>Three.js - Shadertoy Prep</title>
  8. <style>
  9. html, body {
  10. height: 100%;
  11. margin: 0;
  12. }
  13. #c {
  14. width: 100%;
  15. height: 100%;
  16. display: block;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <canvas id="c"></canvas>
  22. </body>
  23. <!-- Import maps polyfill -->
  24. <!-- Remove this when import maps will be widely supported -->
  25. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  26. <script type="importmap">
  27. {
  28. "imports": {
  29. "three": "../../build/three.module.js"
  30. }
  31. }
  32. </script>
  33. <script type="module">
  34. import * as THREE from 'three';
  35. function main() {
  36. const canvas = document.querySelector( '#c' );
  37. const renderer = new THREE.WebGLRenderer( { antialias: true, canvas } );
  38. renderer.autoClearColor = false;
  39. const camera = new THREE.OrthographicCamera(
  40. - 1, // left
  41. 1, // right
  42. 1, // top
  43. - 1, // bottom
  44. - 1, // near,
  45. 1, // far
  46. );
  47. const scene = new THREE.Scene();
  48. const plane = new THREE.PlaneGeometry( 2, 2 );
  49. const material = new THREE.MeshBasicMaterial( {
  50. color: 'red',
  51. } );
  52. scene.add( new THREE.Mesh( plane, material ) );
  53. function resizeRendererToDisplaySize( renderer ) {
  54. const canvas = renderer.domElement;
  55. const width = canvas.clientWidth;
  56. const height = canvas.clientHeight;
  57. const needResize = canvas.width !== width || canvas.height !== height;
  58. if ( needResize ) {
  59. renderer.setSize( width, height, false );
  60. }
  61. return needResize;
  62. }
  63. function render() {
  64. resizeRendererToDisplaySize( renderer );
  65. renderer.render( scene, camera );
  66. requestAnimationFrame( render );
  67. }
  68. requestAnimationFrame( render );
  69. }
  70. main();
  71. </script>
  72. </html>