mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Add support for rendering webgl canvas content (#646)
This commit is contained in:
parent
2237e8e230
commit
250208dc99
14
src/Clone.js
14
src/Clone.js
@ -346,13 +346,13 @@ const cloneCanvasContents = (canvas: HTMLCanvasElement, clonedCanvas: HTMLCanvas
|
|||||||
if (clonedCanvas) {
|
if (clonedCanvas) {
|
||||||
clonedCanvas.width = canvas.width;
|
clonedCanvas.width = canvas.width;
|
||||||
clonedCanvas.height = canvas.height;
|
clonedCanvas.height = canvas.height;
|
||||||
clonedCanvas
|
const ctx = canvas.getContext('2d');
|
||||||
.getContext('2d')
|
const clonedCtx = clonedCanvas.getContext('2d');
|
||||||
.putImageData(
|
if (ctx) {
|
||||||
canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height),
|
clonedCtx.putImageData(ctx.getImageData(0, 0, canvas.width, canvas.height), 0, 0);
|
||||||
0,
|
} else {
|
||||||
0
|
clonedCtx.drawImage(canvas, 0, 0);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
};
|
};
|
||||||
|
@ -7,21 +7,24 @@
|
|||||||
<script type="text/javascript" src="../../test.js"></script>
|
<script type="text/javascript" src="../../test.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function setUp() {
|
function setUp() {
|
||||||
if ($('#testcanvas')[0].getContext) {
|
var ctx = document.querySelector('#testcanvas').getContext('2d');
|
||||||
var ctx = $('#testcanvas')[0].getContext('2d');
|
|
||||||
|
|
||||||
ctx.fillStyle = "rgb(200,0,0)";
|
ctx.fillStyle = "rgb(200,0,0)";
|
||||||
ctx.fillRect (10, 10, 55, 50);
|
ctx.fillRect (10, 10, 55, 50);
|
||||||
|
|
||||||
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
|
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
|
||||||
ctx.fillRect (30, 30, 55, 50);
|
ctx.fillRect (30, 30, 55, 50);
|
||||||
} else {
|
|
||||||
$('#testcanvas').remove();
|
var gl = document.querySelector('#webglcanvas').getContext('webgl', {preserveDrawingBuffer: true});
|
||||||
|
if (gl) {
|
||||||
|
gl.clearColor(0.0, 1.0, 0.0, 1.0);
|
||||||
|
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="testcanvas" style="width:700px;height:300px;"></canvas>
|
<canvas id="testcanvas" style="width:700px;height:300px;"></canvas>
|
||||||
|
<canvas id="webglcanvas" style="width:300px;height:300px;"></canvas>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user