OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library gl_driver; | |
6 | |
7 import 'dart:html'; | |
8 import 'gl.dart'; | |
9 | |
10 /** | |
11 * A driver to run GL applications in the browser. | |
12 */ | |
13 void glMain(setup, resize, draw) { | |
14 // Setup a Canvas for GL to run inside. | |
15 final canvas = new CanvasElement(width: window.innerWidth, height: window.inne
rHeight); | |
16 document.body.nodes.add(canvas); | |
17 | |
18 gl = canvas.getContext('experimental-webgl'); | |
19 | |
20 // The first 'setup' entry point is called once. | |
21 setup(canvas.width, canvas.height); | |
22 | |
23 // The second 'render' entry point is called each time the canvas should | |
24 // be re-drawn. | |
25 var render; | |
26 render = (n) { | |
27 draw(); | |
28 window.requestAnimationFrame(render); | |
29 }; | |
30 render(0); | |
31 | |
32 window.on.resize.add((e) { | |
33 canvas.width = window.innerWidth; | |
34 canvas.height = window.innerHeight; | |
35 resize(canvas.width, canvas.height); | |
36 }); | |
37 } | |
OLD | NEW |