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