-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (89 loc) · 2.96 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>WebGL Boilerplate</title>
<style>
body {
background-color: #000000;
margin: 0px;
overflow: hidden;
}
</style>
</head>
<body>
<canvas></canvas>
<div id="info"></div>
<script type="text/javascript" src="liner.js"></script>
<script type="text/javascript" src="roads.js"></script>
<script>
/**
* Provides requestAnimationFrame in a cross browser way.
* paulirish.com/2011/requestanimationframe-for-smart-animating/
*/
window.requestAnimationFrame = window.requestAnimationFrame || ( function() {
return window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback, element ) {
window.setTimeout( callback, 1000 / 60 );
};
})();
var canvas,
gl,
painter,
parameters = { start_time : new Date().getTime(),
time : 0,
screenWidth : 0,
screenHeight: 0 };
init();
animate();
function init() {
canvas = document.querySelector( 'canvas' );
// Initialise WebGL
try {
gl = canvas.getContext( 'experimental-webgl'
//, {'antialias': false}
);
} catch( error ) { }
if ( !gl ) {
throw "cannot create webgl context";
}
painter = liner.createPainter(gl);
//liner.createData(painter);
liner.addLines(painter, ROADS);
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize( event ) {
var desiredWidthInCSSPixels = window.innerWidth;
var desiredHeightInCSSPixels = window.innerHeight;
//var canvas = document.getElementById("myCanvas");
// set the display size of the canvas.
canvas.style.width = desiredWidthInCSSPixels + "px";
canvas.style.height = desiredHeightInCSSPixels + "px";
// set the size of the drawingBuffer
var devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = desiredWidthInCSSPixels * devicePixelRatio;
canvas.height = desiredHeightInCSSPixels * devicePixelRatio;
//canvas.width = window.innerWidth;
//canvas.height = window.innerHeight;
//parameters.screenWidth = canvas.width;
//parameters.screenHeight = canvas.height;
parameters.screenWidth = desiredWidthInCSSPixels
parameters.screenHeight = desiredHeightInCSSPixels
gl.viewport( 0, 0, canvas.width, canvas.height );
//painter.updateResolution(parameters.screenWidth, parameters.screenHeight);
}
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
painter.draw({resolution: {width: parameters.screenWidth, height: parameters.screenHeight}});
}
</script>
</body>
</html>