|
14 | 14 |
|
15 | 15 | window.onload = () => {
|
16 | 16 | const canvas = document.querySelector("#glcanvas");
|
17 |
| - const gl = canvas.getContext("webgl"); |
| 17 | + const gl = canvas.getContext("webgl2"); |
18 | 18 |
|
19 | 19 | if (gl === null) {
|
20 | 20 | alert(
|
|
34 | 34 | canvas.style.height = window.innerHeight + 'px';
|
35 | 35 | })();
|
36 | 36 |
|
37 |
| - const vsSource = ` |
38 |
| - attribute vec4 a_vpos; |
39 |
| - attribute float a_palette_index; |
| 37 | + const vsSource = `#version 300 es |
| 38 | + precision mediump float; |
40 | 39 |
|
41 |
| - varying float v_palette_index; |
| 40 | + in vec4 a_vpos; |
| 41 | + in float a_palette_index; |
| 42 | + |
| 43 | + flat out int v_palette_index; |
42 | 44 |
|
43 | 45 | void main(void) {
|
44 |
| - v_palette_index = a_palette_index; |
| 46 | + v_palette_index = int(round(a_palette_index)); |
45 | 47 | gl_Position = a_vpos;
|
46 | 48 | }
|
47 | 49 | `;
|
48 | 50 |
|
49 |
| - const fsSource = ` |
50 |
| - varying lowp float v_palette_index; |
| 51 | + const fsSource = `#version 300 es |
| 52 | + precision mediump float; |
| 53 | + |
| 54 | + flat in int v_palette_index; |
| 55 | + |
| 56 | + out vec4 color; |
51 | 57 |
|
52 | 58 | void main(void) {
|
53 |
| - gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); |
54 |
| - if (0.0 == v_palette_index) gl_FragColor = vec4(0.8, 0.1, 0.1, 1.0); |
55 |
| - if (1.0 == v_palette_index) gl_FragColor = vec4(0.1, 0.8, 0.1, 1.0); |
56 |
| - if (2.0 == v_palette_index) gl_FragColor = vec4(0.1, 0.1, 0.8, 1.0); |
57 |
| - if (3.0 == v_palette_index) gl_FragColor = vec4(1.0, 0.4, 0.4, 1.0); |
58 |
| - if (4.0 == v_palette_index) gl_FragColor = vec4(0.4, 1.0, 0.4, 1.0); |
59 |
| - if (5.0 == v_palette_index) gl_FragColor = vec4(0.4, 0.4, 1.0, 1.0); |
| 59 | + color = vec4(1.0, 0.0, 1.0, 1.0); |
| 60 | + if (0 == v_palette_index) color = vec4(0.8, 0.1, 0.1, 1.0); |
| 61 | + if (1 == v_palette_index) color = vec4(0.1, 0.8, 0.1, 1.0); |
| 62 | + if (2 == v_palette_index) color = vec4(0.1, 0.1, 0.8, 1.0); |
| 63 | + if (3 == v_palette_index) color = vec4(1.0, 0.4, 0.4, 1.0); |
| 64 | + if (4 == v_palette_index) color = vec4(0.4, 1.0, 0.4, 1.0); |
| 65 | + if (5 == v_palette_index) color = vec4(0.4, 0.4, 1.0, 1.0); |
60 | 66 |
|
61 | 67 | // gl_FragColor *= 0.6;
|
62 | 68 | }
|
|
203 | 209 | ibuf = new Uint16Array(8192 / 2);
|
204 | 210 |
|
205 | 211 | function line(a, b, a_thick, b_thick, c, z_push=0) {
|
206 |
| - const aspect_ratio = gl.canvas.clientWidth / gl.canvas.clientHeight; |
207 |
| - |
208 | 212 | mat4_transform_vec4(a, a, u_mvp);
|
209 | 213 | mat4_transform_vec4(b, b, u_mvp);
|
210 | 214 |
|
211 | 215 | const dx = b[0] - a[0];
|
212 | 216 | const dy = b[1] - a[1];
|
213 |
| - const nx = -dy; /* perp */ |
214 |
| - const ny = dx*aspect_ratio; |
| 217 | + const nx = -dy; |
| 218 | + const ny = dx; |
215 | 219 | const tlen = Math.sqrt(nx*nx + ny*ny);
|
216 | 220 | if (tlen <= 0) return;
|
217 |
| - let a_tx = nx/tlen * 0.5*a_thick / aspect_ratio; |
| 221 | + let a_tx = nx/tlen * 0.5*a_thick; |
218 | 222 | let a_ty = ny/tlen * 0.5*a_thick;
|
219 |
| - let b_tx = nx/tlen * 0.5*b_thick / aspect_ratio; |
| 223 | + let b_tx = nx/tlen * 0.5*b_thick; |
220 | 224 | let b_ty = ny/tlen * 0.5*b_thick;
|
221 | 225 |
|
222 | 226 | ibuf[ibuf_i++] = 0 + vbuf_i/5;
|
|
0 commit comments