Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (57 sloc) 1.89 KB
<!DOCTYPE html>
<title>WebGL-2D Example</title>
<script src="../webgl-2d.js" type="text/javascript"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", init, false);
var cvs2D, cvsGL, ctx2D, ctxGL, width, height;
var frameCount = 0;
function init() {
cvs2D = document.getElementById("canvas2D");
cvsGL = document.getElementById("canvasGL");
width = cvs2D.width, height = cvs2D.height;
WebGL2D.enable(cvsGL); // adds new context "webgl-2d" to cvs
// Easily switch between regular canvas 2d context and webgl-2d
ctx2D = cvs2D.getContext("2d");
ctxGL = cvsGL.getContext("webgl-2d");
// Enable animation
//setInterval(function() { frameCount++; draw(ctxGL); draw(ctx2D); }, 1000/30);
function draw(ctx) {
ctx.fillStyle = "rgb(50, 0, 50)";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = "rgba(50, 255, 255, 0.1)";
ctx.translate(width/2, width/2);;
for (var i=1; i<256; i*=1.15) {
ctx.translate(i*2, 0);
ctx.fillRect(-i, -i, i*2, i*2);
} //for
<style type="text/css">
body, * {
font-family: sans-serif;
<h1>Example: WebGL-2D Comparison</h1>
<h2>transform stack</h2>
<div style="float: left; margin-right: 10px;">
<canvas id="canvasGL" width="350" height="350" style="border: 1px solid black;"></canvas>
<div style="float: left;">
<canvas id="canvas2D" width="350" height="350" style="border: 1px solid black;"></canvas>