OLD | NEW |
| (Empty) |
1 <html><head> | |
2 | |
3 | |
4 <title>GLGE</title> | |
5 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> | |
6 | |
7 | |
8 <script type="text/javascript" src="glge-compiled-min.js"></script> | |
9 <style> | |
10 body { | |
11 background-color: #000; | |
12 color: #fff; | |
13 font-family:arial; | |
14 margin:0; | |
15 overflow:hidden; | |
16 } | |
17 </style> | |
18 </head><body> | |
19 | |
20 <div id="dump"></div> | |
21 | |
22 <div> | |
23 | |
24 <canvas id="canvas" width="900" | |
25 height="500"></canvas> | |
26 <div id="power" style="position:absolute; left: 50px; top: 20px; height: 30px; w
idth: 230px;"> | |
27 Powered By <a style="color:#0f0;text-decoration:none;" href="http://www.glge.org
">GLGE</a> | |
28 </div> | |
29 <div id="framerate" style="position:absolute; right: 50px; top: 20px; height: 30
px; width: 130px;"> | |
30 <div id="debug" style="padding: 5px"></div> | |
31 </div> | |
32 | |
33 | |
34 </div> | |
35 | |
36 <script type="text/javascript"> | |
37 | |
38 | |
39 var canvas=document.getElementById('canvas'); | |
40 | |
41 var doc = new GLGE.Document(); | |
42 doc.onLoad=function(){ | |
43 //create the renderer | |
44 var gameRenderer=new GLGE.Renderer(canvas); | |
45 //gameScene=new GLGE.Scene(); | |
46 gameScene=doc.getElement("mainscene"); | |
47 var camera=doc.getElement("maincamera"); | |
48 var lookat=doc.getElement("lookat"); | |
49 var logo=doc.getElement("logo"); | |
50 var blue1=doc.getElement("blue1"); | |
51 var blue2=doc.getElement("blue2"); | |
52 var cloudmaterial=doc.getElement("cloudmaterial"); | |
53 var bots=doc.getElement("bots"); | |
54 var cloud=doc.getElement("cloud"); | |
55 | |
56 gameRenderer.setScene(gameScene); | |
57 | |
58 filter=new GLGE.Filter2d(); | |
59 filter.setEmitBufferWidth(256); | |
60 filter.setEmitBufferHeight(256); | |
61 filter.renderEmit=true; | |
62 gameScene.setFilter2d(filter); | |
63 | |
64 //god rays and sky | |
65 filter.addPassFile("emit1.glsl"); | |
66 filter.addPassFile("emit2.glsl"); | |
67 | |
68 | |
69 logo.addEventListener("downloadComplete",function(){ | |
70 var injection=[]; | |
71 injection.push("uniform float time;\n"); | |
72 injection.push("vec4 GLGE_Position(vec4 pos){\n"); | |
73 injection.push("pos.x=pos.x+sin((pos.x*10.0+time*10.0)*0.167)*0.1;\n"); | |
74 injection.push("pos.y=pos.y+cos((pos.y*10.0+time*10.0)*0.25)*0.1;\n"); | |
75 injection.push("return pos;\n"); | |
76 injection.push("}\n"); | |
77 this.getObjects()[0].setVertexShaderInjection(injection.join("")); | |
78 }); | |
79 | |
80 | |
81 var positions=[]; | |
82 for(var i=-20;i<20;i++){ | |
83 positions.push(0); | |
84 positions.push(0); | |
85 positions.push(i/2+10); | |
86 positions.push(0); | |
87 positions.push(0); | |
88 positions.push((i+1)/2+10); | |
89 } | |
90 | |
91 function makeLine(mat, rot) | |
92 { | |
93 var line=(new GLGE.Object).setDrawType(GLGE.DRAW_LINES).setLineWidth(3); | |
94 line.setMesh((new GLGE.Mesh).setPositions(positions)); | |
95 line.setMaterial(blue1); | |
96 line.setRotY(rot); | |
97 return line; | |
98 | |
99 } | |
100 var line1=makeLine(blue1, 0); | |
101 bots.addObject(line1); | |
102 var line2=makeLine(blue1, 1.57); | |
103 bots.addObject(line2); | |
104 var line3=makeLine(blue1, 3.14); | |
105 bots.addObject(line3); | |
106 var line4=makeLine(blue1, 4.71); | |
107 bots.addObject(line4); | |
108 | |
109 var positions=[]; | |
110 for(var i=0;i<1000;i++){ | |
111 var v=GLGE.toUnitVec3([(Math.random()-0.5)*2,(Math.random()-0.5)*2,(Math.ran
dom()-0.5)*2]); | |
112 positions.push(v[0]*Math.random()*Math.random()*50); | |
113 positions.push(v[1]*Math.random()*Math.random()*10); | |
114 positions.push(v[2]*Math.random()*Math.random()*50); | |
115 } | |
116 | |
117 var points=(new GLGE.Object).setDrawType(GLGE.DRAW_POINTS).setPointSize(2); | |
118 points.setMesh((new GLGE.Mesh).setPositions(positions)); | |
119 points.setMaterial(cloudmaterial); | |
120 cloud.addObject(points); | |
121 points.setZtransparent(true); | |
122 | |
123 var injection=[]; | |
124 injection.push("uniform float time;\n"); | |
125 injection.push("vec4 GLGE_Position(vec4 pos){\n"); | |
126 | |
127 injection.push("pos.z=pos.z+(fract(sin(dot(pos.xy+vec2(time) ,vec2(12.9898,78.23
3))) * 43758.5453)-0.5)*0.5;\n"); | |
128 injection.push("pos.y=pos.y+(fract(sin(dot(pos.zx+vec2(time) ,vec2(12.9898,78.23
3))) * 43758.5453)-0.5)*0.5;\n"); | |
129 injection.push("return pos;\n"); | |
130 injection.push("}\n"); | |
131 line1.setVertexShaderInjection(injection.join("")); | |
132 line2.setVertexShaderInjection(injection.join("")); | |
133 line3.setVertexShaderInjection(injection.join("")); | |
134 line4.setVertexShaderInjection(injection.join("")); | |
135 | |
136 | |
137 | |
138 var lasttime=0; | |
139 var frameratebuffer=60; | |
140 start=parseInt(new Date().getTime()); | |
141 var now; | |
142 function render(){ | |
143 console.log("render"); | |
144 now=parseInt(new Date().getTime()); | |
145 | |
146 logo.getObjects()[0].setUniform("1f","time",(now-start)/1000); | |
147 line1.setUniform("1f","time",(now-start)/1000); | |
148 line2.setUniform("1f","time",(now-start)/1000); | |
149 line3.setUniform("1f","time",(now-start)/1000); | |
150 line4.setUniform("1f","time",(now-start)/1000); | |
151 points.setUniform("1f","time",(now-start)/1000); | |
152 | |
153 frameratebuffer=Math.round(((frameratebuffer*9)+1000/(now-lasttime))/10); | |
154 document.getElementById("debug").innerHTML="Frame Rate:"+frameratebuffer
; | |
155 gameRenderer.render(); | |
156 lasttime=now; | |
157 } | |
158 setInterval(render,15); | |
159 | |
160 function mouseMove(x, y) | |
161 { | |
162 //if (x < 0 || y < 0) | |
163 } | |
164 | |
165 canvas.onmousemove=function(e){ | |
166 //camera.setLocX((e.clientX/canvas.width-0.5)*70); | |
167 //camera.setLocZ((e.clientY/canvas.height-0.5)*50+5); | |
168 //lookat.setLocX((e.clientX/canvas.width-0.5)*-70); | |
169 //lookat.setLocZ((e.clientY/canvas.height-0.5)*-50+5); | |
170 } | |
171 | |
172 canvas.onblur=function(e){ | |
173 } | |
174 | |
175 } | |
176 doc.load("level.xml"); | |
177 </script> | |
178 | |
179 </body></html> | |
OLD | NEW |