-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample_tex.html
94 lines (85 loc) · 1.76 KB
/
sample_tex.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
<!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],
},
texture:[
{src:"res/tex2.jpg"}
],
model:[
{ //model1
geo:{mode:"tri_strip",
vtx_at:["position","uv"],
vtx:[
1,1,0,//pos
1.0,1.0,//uv
1,-1,0,
1.0,0,
-1,1,0,
0,1.0,
-1,-1,0,
0,0
],
idx:[0,1,2,3]},
fs_uni:{
tex1:0
},
}
]
}
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) ;
})
// while(1) {} ;
} //onload
</script>
<! --------------- Vertex Shader ---------------- ->
<script id="vshader" type="x-shader/x-vertex">
uniform mat4 mvpMatrix;
attribute vec3 position;
attribute vec2 uv;
varying vec2 texCoord;
void main() {
texCoord = vec2(uv.x,-uv.y);
gl_Position = mvpMatrix * vec4(position, 1.0) ;
}
</script>
<! --------------- Fragment Shader ---------------- ->
<script id="fshader" type="x-shader/x-fragment">
precision highp float;
uniform sampler2D tex1;
varying vec2 texCoord;
void main() {
gl_FragColor = texture2D(tex1, texCoord);
}
</script>
</head>
<body>
<canvas id="screen1" width="400px" height="400px"></canvas>