-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_min.html
85 lines (77 loc) · 1.66 KB
/
sample_min.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WWG simple sample</title>
<script src="js/WWG.js"></script>
<script>
onload = function() {
var render = {
env:{clear_color:[0.5,0.5,0.6,1.0]},
vshader:{
text: document.getElementById('vshader').innerText
},
fshader:{
text: document.getElementById('fshader').innerText
},
vs_uni:{
mvpMatrix:[0.5,0,0,0, 0,0.5,0,0, 0,0,1,0, 0,0,0,1],
},
model:[
{ //model1
geo:{mode:"tri_strip",
vtx_at:["position","vcolor"],
vtx:[
1,1,0,//pos
1.0,0,0,1.0,//vcolor
1,-1,0,
0,1.0,0,1.0,
-1,1,0,
0,0,1.0,1.0,
-1,-1,0,
1.0,1.0,1.0,1.0
],
idx:[0,1,2,3]}
}
]
}
var wwg = new WWG() ;
if(!wwg.init(document.getElementById('screen1'))) {
alert("not supported") ;
return ;
}
console.log(wwg) ;
//create render unit
var r = wwg.createRender() ;
//parse render data
r.setRender(render).then(function() {
console.log(r) ;
r.draw() ;
}).catch(function(err){
console.log("err") ;
console.log(err) ;
})
} //onload
</script>
<! --------------- Vertex Shader ---------------- ->
<script id="vshader" type="x-shader/x-vertex">
uniform mat4 mvpMatrix;
attribute vec3 position;
attribute vec4 vcolor ;
varying vec4 pcolor;
void main() {
pcolor = vcolor;
gl_Position = mvpMatrix * vec4(position, 1.0) ;
}
</script>
<! --------------- Fragment Shader ---------------- ->
<script id="fshader" type="x-shader/x-fragment">
precision highp float;
varying vec4 pcolor;
void main() {
gl_FragColor = pcolor ;
}
</script>
</head>
<body>
<canvas id="screen1" width="400px" height="400px"></canvas>