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 /** | 5 /** |
6 * A sample GL application. | 6 * A sample GL application. |
7 */ | 7 */ |
8 library flashingbox; | 8 library flashingbox; |
9 | 9 |
10 import 'gl.dart'; | 10 import 'gl.dart'; |
11 | 11 |
| 12 WebGLRenderingContext gl = null; |
| 13 |
12 num r; | 14 num r; |
13 num g; | 15 num g; |
14 num b; | 16 num b; |
15 | 17 |
16 /** | 18 void setup(canvas, int w, int h, int f) { |
17 * Invoked on initial startup. | 19 if (canvas == null) { |
18 */ | 20 canvas = new CanvasElement(width: w, height: h); |
19 void setup(int width, int height) { | 21 } |
| 22 gl = canvas.getContext("experimental-webgl"); |
20 r = 0; | 23 r = 0; |
21 g = 0; | 24 g = 0; |
22 b = 0; | 25 b = 0; |
23 resize(width, height); | 26 resize(w, h); |
| 27 window.requestAnimationFrame(update); |
| 28 log("Done setup"); |
24 } | 29 } |
25 | 30 |
26 void resize(int width, int height) { | 31 void resize(int width, int height) { |
27 gl.viewport(0, 0, width, height); | 32 gl.viewport(0, 0, width, height); |
28 } | 33 } |
29 | 34 |
30 /** | 35 void update(when) { |
31 * Invoked on each frame render. | |
32 */ | |
33 void draw() { | |
34 gl.clearColor(r, g, b, 1.0); | 36 gl.clearColor(r, g, b, 1.0); |
35 gl.clear(WebGLRenderingContext.COLOR_BUFFER_BIT | | 37 gl.clear(WebGLRenderingContext.COLOR_BUFFER_BIT | |
36 WebGLRenderingContext.DEPTH_BUFFER_BIT); | 38 WebGLRenderingContext.DEPTH_BUFFER_BIT); |
37 r = r + 0.1; | 39 r = r + 0.1; |
38 if (r > 1) { | 40 if (r > 1) { |
39 r = 0; | 41 r = 0; |
40 g = g + 0.1; | 42 g = g + 0.1; |
41 } | 43 } |
42 if (g > 1) { | 44 if (g > 1) { |
43 g = 0; | 45 g = 0; |
44 b = b + 0.1; | 46 b = b + 0.1; |
45 } | 47 } |
46 if (b > 1) { | 48 if (b > 1) { |
47 b = 0; | 49 b = 0; |
48 } | 50 } |
| 51 glSwapBuffers(); |
| 52 window.requestAnimationFrame(update); |
49 } | 53 } |
| 54 |
OLD | NEW |