-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoints.js
111 lines (78 loc) · 2.88 KB
/
points.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Created by Niklas Hennings @ 3henning on 26.10.15.
* Based on a template by ICG @ HCI.
*/
var gl;
// Specify position of the vertices
var vertices = new Float32Array([-0.5, 0,
0.5, 0]);
var size = new Float32Array([64.0,
64.0]);
window.onload = function init()
{
// Get canvas and setup webGL
var canvas = document.getElementById("gl-canvas");
gl = WebGLUtils.setupWebGL(canvas);
if (!gl) { alert("WebGL isn't available"); }
// Specify color of the vertices
var colors = new Float32Array([ 1, 0, 0, 1,
0, 0, 1, 1]);
if ("".localeCompare(location.search) != 0)
{
var info = location.search.split("&");
info[0] = info[0].substring(6);
info[1] = info[1].substring(5);
process(info[0], info[1]);
}
// Configure viewport
gl.viewport(0,0,canvas.width,canvas.height);
gl.clearColor(1.0,1.0,1.0,1.0);
// Init shader program and bind it
var program = initShaders(gl, "vertex-shader", "fragment-shader");
gl.useProgram(program);
// Load colors into the GPU and associate shader variables
var cBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, cBuffer);
gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
var vColor = gl.getAttribLocation(program, "vColor");
gl.vertexAttribPointer(vColor, 4, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vColor);
// Load positions into the GPU and associate shader variables
var bufferId = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, bufferId);
gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW);
var vPosition = gl.getAttribLocation(program, "vPosition");
gl.vertexAttribPointer(vPosition, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vPosition);
// Load squares' size into the GPU and associate shader variables
var sizeBufferId = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, sizeBufferId);
gl.bufferData(gl.ARRAY_BUFFER, size, gl.STATIC_DRAW);
var vSize = gl.getAttribLocation(program, "vSize");
gl.vertexAttribPointer(vSize, 1, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(vSize);
render();
};
function render()
{
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.POINTS, 0, 2);
}
function process(diam, unit)
{
var ratio = screen.width / screen.height;
if (unit.localeCompare("Zoll") == 0)
{
diam *= 25.4;
}
else
{
diam *= 10.0;
}
var hoehe = (diam) / Math.sqrt(Math.pow(ratio, 2) + 1.0);
// var breite = hoehe * ratio;
var pixelPerMM = screen.height / hoehe;
size = new Float32Array([pixelPerMM, pixelPerMM]);
var unitPerPixel = 2.0 / document.getElementById("gl-canvas").width;
vertices.set(new Float32Array([(vertices[0] + ((2 * pixelPerMM) * unitPerPixel))]), 2);
}