diff options
Diffstat (limited to 'graphics/asymptote/webgl/gl.js')
-rw-r--r-- | graphics/asymptote/webgl/gl.js | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/graphics/asymptote/webgl/gl.js b/graphics/asymptote/webgl/gl.js index f3bdf5505f..4aab28909c 100644 --- a/graphics/asymptote/webgl/gl.js +++ b/graphics/asymptote/webgl/gl.js @@ -56,6 +56,7 @@ let P=[]; // Array of Bezier patches, triangles, curves, and pixels let Materials=[]; // Array of materials let Lights=[]; // Array of lights let Centers=[]; // Array of billboard centers +let Background=[1,1,1,1]; // Background color // Don't account for device pixels when embedding in another html document let absolute=false; @@ -153,7 +154,7 @@ class Light { function initGL() { try { - gl=canvas.getContext("webgl",{alpha:false}); // Don't composite background + gl=canvas.getContext("webgl",{alpha:Background[3] < 1}); } catch(e) {} if (!gl) alert("Could not initialize WebGL"); @@ -1587,10 +1588,10 @@ function pinchDistance(touches) let touchStartTime; -function handleTouchStart(evt) +function handleTouchStart(event) { - evt.preventDefault(); - let touches=evt.targetTouches; + event.preventDefault(); + let touches=event.targetTouches; swipe=rotate=pinch=false; if(zooming) return; @@ -1785,6 +1786,8 @@ function handleKey(event) function handleMouseWheel(event) { + event.preventDefault(); + if (event.deltaY < 0) { Zoom *= zoomFactor; } else { @@ -1823,11 +1826,11 @@ let zooming=false; let swipe=false; let rotate=false; -function handleTouchMove(evt) +function handleTouchMove(event) { - evt.preventDefault(); + event.preventDefault(); if(zooming) return; - let touches=evt.targetTouches; + let touches=event.targetTouches; if(!pinch && touches.length == 1 && touchId == touches[0].identifier) { let newX=touches[0].pageX; @@ -1897,7 +1900,7 @@ function transformVertices(vertices) function draw() { - gl.clearColor(1,1,1,1); + gl.clearColor(Background[0],Background[1],Background[2],Background[3]); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); material0Data.clear(); @@ -2127,8 +2130,8 @@ function webGLStart() document.onmouseup=handleMouseUpOrTouchEnd; document.onmousemove=handleMouseMove; canvas.onkeydown=handleKey; - document.onwheel=handleMouseWheel; + canvas.addEventListener("wheel",handleMouseWheel,false); canvas.addEventListener("touchstart",handleTouchStart,false); canvas.addEventListener("touchend",handleMouseUpOrTouchEnd,false); canvas.addEventListener("touchcancel",handleMouseUpOrTouchEnd,false); |