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