Parcourir la Source

add a simple editor

Lucas Stadler 10 ans auparavant
Parent
commit
6430454e66
1 fichiers modifiés avec 42 ajouts et 0 suppressions
  1. 42 0
      glsl/raymarching.js

+ 42 - 0
glsl/raymarching.js

25
    console.error(e);
25
    console.error(e);
26
  }
26
  }
27
  
27
  
28
  function clearError() {
29
    errorEl.textContent = "";
30
  }
31
  
28
  function compileShader(gl, type, shaderSrc) {
32
  function compileShader(gl, type, shaderSrc) {
29
    var shader = gl.createShader(type);
33
    var shader = gl.createShader(type);
30
    gl.shaderSource(shader, shaderSrc);
34
    gl.shaderSource(shader, shaderSrc);
217
  transition: right 0.1s;
221
  transition: right 0.1s;
218
  right: 0;
222
  right: 0;
219
}
223
}
224
225
#editor {
226
  position: absolute;
227
  top: 0;
228
  left: 0;
229
230
  border: none;
231
  background-color: rgba(255, 255, 255, 0.5);
232
233
  min-width: 72ex;
234
  height: 100vh;
235
}
220
  `
236
  `
221
  document.head.appendChild(styleEl);
237
  document.head.appendChild(styleEl);
222
  
238
  
305
  addSliders(sidebarEl, sliders);
321
  addSliders(sidebarEl, sliders);
306
  
322
  
307
  tt.render();
323
  tt.render();
324
  
325
  var editor = {};
326
  editor.el = document.createElement("textarea");
327
  editor.el.id = "editor";
328
  editor.el.value = fragmentShaderSrc;
329
  document.body.appendChild(editor.el);
330
  
331
  editor.el.onkeydown = function(ev) {
332
    try {
333
      if (ev.ctrlKey && ev.keyCode == 13) {
334
        tt = TwoTriangles(canvas, editor.el.value);
335
336
        sidebarEl.innerHTML = "";
337
        sliders = findSliders(fragmentShaderSrc);
338
        initSliders(tt.gl, tt.program, sliders, function(ev) {
339
          requestAnimationFrame(tt.render);
340
        });
341
        addSliders(sidebarEl, sliders);
342
343
        tt.render();
344
        clearError();
345
      }
346
    } catch (e) {
347
      displayError(e);
348
    }
349
  }
308
} catch (e) {
350
} catch (e) {
309
  displayError(e);
351
  displayError(e);
310
}
352
}