| 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; | 5 library gl_driver; |
| 6 | 6 |
| 7 import 'dart:html'; | |
| 8 import '../src/gl.dart'; | 7 import '../src/gl.dart'; |
| 9 | 8 |
| 10 /** | 9 /** |
| 11 * A driver to run GL applications in the browser. | 10 * A driver to run GL applications in the browser. |
| 12 */ | 11 */ |
| 13 | 12 |
| 14 bool is3d = false; | 13 void glMain(setup, resize, draw, [onMotionDown]) { |
| 15 | |
| 16 void glMain(setup, resize, draw, onMotionDown) { | |
| 17 // Setup a Canvas for GL to run inside. | 14 // Setup a Canvas for GL to run inside. |
| 18 final canvas = new CanvasElement(width: window.innerWidth, | 15 final canvas = getDisplayCanvas(resize); |
| 19 height: window.innerHeight); | |
| 20 document.body.nodes.add(canvas); | |
| 21 | |
| 22 // The first 'setup' entry point is called once. | |
| 23 setup(canvas, canvas.width, canvas.height); | 16 setup(canvas, canvas.width, canvas.height); |
| 24 | 17 |
| 25 canvas.on.mouseDown.add((e) { | 18 canvas.on.mouseDown.add((e) { |
| 26 onMotionDown(0, 0, 0); | 19 if (onMotionDown != null) { |
| 20 onMotionDown(0, 0, 0); |
| 21 } |
| 27 }); | 22 }); |
| 28 // The second 'render' entry point is called each time the canvas should | |
| 29 // be re-drawn. | |
| 30 var render; | |
| 31 render = (n) { | |
| 32 draw(); | |
| 33 window.requestAnimationFrame(render); | |
| 34 }; | |
| 35 render(0); | |
| 36 | 23 |
| 37 window.onResize.listen((e) { | 24 animate(draw); |
| 38 canvas.width = window.innerWidth; | |
| 39 canvas.height = window.innerHeight; | |
| 40 resize(canvas.width, canvas.height); | |
| 41 }); | |
| 42 } | 25 } |
| 26 |
| OLD | NEW |