This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spider2.html
248 lines (193 loc) · 5.74 KB
/
spider2.html
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!--?xml version="1.0" encoding="UTF-8"?-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<meta http-equiv="PRAGMA" content="NO-CACHE">
</head><body id="index"><object><noscript><p></p></noscript></object>
<!-- End Piwik Tag -->
<title>SpiderGL - Basic Mesh Rendering</title>
<!--
<meta name="keywords" content=""/>
<meta name="description" content=""/>
-->
<div class="container">
<div id="header" class="span-24 last">
<div class="span-24 last">
<script type="text/javascript" src="js/spidergl.js"></script>
<script id="SIMPLE_VERTEX_SHADER" type="text/x-vertex">
#ifdef GL_ES
precision highp float;
#endif
uniform mat4 u_mvp;
attribute vec3 a_position;
attribute vec3 a_color;
varying vec3 v_color;
void main(void)
{
v_color = a_color;
gl_Position = u_mvp * vec4(a_position, 1.0);
}
</script>
<script id="SIMPLE_FRAGMENT_SHADER" type="text/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
varying vec3 v_color;
void main(void)
{
gl_FragData[0] = vec4(v_color, 1.0);
}
</script>
<script type="text/javascript">
function log(msg)
{
document.getElementById("LOG").innerHTML += (msg + "\n");
}
function SpiderGLExample1()
{
;
}
SpiderGLExample1.prototype =
{
load : function(gl)
{
log("SpiderGL Version : " + SGL_VERSION_STRING + "\n");
/*************************************************************/
this.xform = new SglTransformStack();
this.angle = 0.0;
this.primitives = "triangles";
/*************************************************************/
/*************************************************************/
var simpleVsrc = sglNodeText("SIMPLE_VERTEX_SHADER");
var simpleFsrc = sglNodeText("SIMPLE_FRAGMENT_SHADER");
var simpleProg = new SglProgram(gl, [simpleVsrc], [simpleFsrc]);
log(simpleProg.log);
this.simpleProg = simpleProg;
/*************************************************************/
/*************************************************************/
var boxPositions = new Float32Array
([
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
-0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
-0.5, 0.5, -0.5,
0.5, 0.5, -0.5
]);
var boxColors = new Float32Array
([
0.0, 0.0, 1.0,
1.0, 0.0, 1.0,
0.0, 1.0, 1.0,
1.0, 1.0, 1.0,
0.0, 0.0, 0.0,
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
1.0, 1.0, 0.0
]);
var boxTrianglesIndices = new Uint16Array
([
0, 1, 2, 2, 1, 3, // front
5, 4, 7, 7, 4, 6, // back
4, 0, 6, 6, 0, 2, // left
1, 5, 3, 3, 5, 7, // right
2, 3, 6, 6, 3, 7, // top
4, 5, 0, 0, 5, 1 // bottom
]);
var boxEdgesIndices = new Uint16Array
([
0, 1, 1, 3, 3, 2, 2, 0, // front
5, 4, 4, 6, 6, 7, 7, 5, // back
0, 4, 1, 5, 3, 7, 2, 6 // middle
]);
var box = new SglMeshGL(gl);
box.addVertexAttribute("position", 3, boxPositions);
box.addVertexAttribute("color", 3, boxColors);
box.addArrayPrimitives("vertices", gl.POINTS, 0, 8);
box.addIndexedPrimitives("triangles", gl.TRIANGLES, boxTrianglesIndices);
box.addIndexedPrimitives("edges", gl.LINES, boxEdgesIndices);
this.boxMesh = box;
/*************************************************************/
},
keyPress : function(gl, keyCode, keyString)
{
switch (keyString)
{
case "1": this.primitives = "triangles"; break;
case "2": this.primitives = "edges"; break;
case "3": this.primitives = "vertices"; break;
default : break;
}
},
update : function(gl, dt)
{
this.angle += 90.0 * dt;
},
draw : function(gl)
{
var w = this.ui.width;
var h = this.ui.height;
gl.clearColor(0.2, 0.2, 0.6, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
gl.viewport(0, 0, w, h);
this.xform.projection.loadIdentity();
this.xform.projection.perspective(sglDegToRad(60.0), w/h, 0.1, 100.0);
this.xform.view.loadIdentity();
this.xform.view.lookAt(0.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
this.xform.model.loadIdentity();
this.xform.model.rotate(sglDegToRad(this.angle), 0.0, 1.0, 0.0);
this.xform.model.scale(1.5, 1.5, 1.5);
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.CULL_FACE);
var boxUniforms = { u_mvp : this.xform.modelViewProjectionMatrix };
sglRenderMeshGLPrimitives(this.boxMesh, this.primitives, this.simpleProg, null, boxUniforms);
gl.disable(gl.DEPTH_TEST);
gl.disable(gl.CULL_FACE);
}
};
sglRegisterCanvas("SGL_CANVAS1", new SpiderGLExample1(), 60.0);
</script>
<div class="span-22 prepend-1 last">
<canvas id="SGL_CANVAS1" width="800" height="420" contenteditable="true"></canvas>
<p></p>
</div>
<div class="span-12 prepend-1">
<h4>Description</h4>
<p>This example shows how to draw a basic triangle mesh and basic user interaction</p>
</div>
<div class="span-8 prepend-1 last">
<h4>Controls</h4>
<p>
Press "1" for solid rendering.<br>
Press "2" for wireframe rendering.<br>
Press "3" for vertex rendering.
</p>
</div>
<div class="span-22 prepend-1 last">
<h4>Log</h4>
<textarea id="LOG" style="width: 800px; height: 200px;">SpiderGL Version : 0.1.1
-------------------------------------
----------------------
[SHADER LOG]
SUCCESS:
----------------------
----------------------
[SHADER LOG]
SUCCESS:
----------------------
----------------------
[PROGRAM LOG]
SUCCESS:
----------------------
-------------------------------------
</textarea>
</div>
</div>
<div id="footer" class="span-23 prepend-1 last">
<p>A <a href="http://vcg.isti.cnr.it/">Visual Computing Laboratory - ISTI - CNR</a> initiative</p>
</div>
</div>
</body></html>