Commits

Sebastien Mondet  committed 04dce34

webpdb,mk: get 2 triangles displayed

  • Participants
  • Parent commits d3ddafe

Comments (0)

Files changed (2)

   <head>
     <meta charset="utf-8">
     <title>PDB Demo Web-Viewer</title>
+
+<style type="text/css">
+<!--
+body {background-color:black; color:white}
+canvas {float:left;}
+-->
+</style>
+<script id="vertex-shader" type="x-shader/x-vertex">
+  attribute vec3 a_position;
+  attribute vec3 a_normal;
+
+  uniform mat4 u_proj;
+
+  varying mediump vec3 v_position;
+  varying mediump vec3 v_normal;
+
+  void main() {
+    vec4 pos = u_proj * vec4(a_position,1);
+    vec4 norm = u_proj * vec4(a_normal,1);
+    v_position = pos.xyz;
+    v_normal = norm.xyz;
+    gl_Position = pos;
+  }
+</script>
+<script id="fragment-shader" type="x-shader/x-fragment">
+  precision mediump float;
+  varying vec3 v_position;
+  varying vec3 v_normal;
+
+  uniform vec3 u_lightPos;
+  uniform vec3 u_ambientLight;
+
+  void main() {
+    vec3 lightDirection = normalize(u_lightPos - v_position);
+    float lighting = max(dot(normalize(v_normal), lightDirection), 0.);
+    vec3 col = vec3(1,1,1);
+    gl_FragColor = vec4( col * lighting + u_ambientLight, 1);
+  }
+</script>
     <script src="./webpdb.js"></script>
   </head>
   <body>
+    <canvas id="canvas" height="400" width="400"></canvas>
+    <div><span id="fps"></span> frames per second</div>
   </body>
 </html>
 EOF
                 *. (Pervasives.float (Queue.length draw_times))
                 *. 1000. in
       fps_text##data <- string (Printf.sprintf "%.1f" fps);
-      Lwt_js.sleep 0.02 >>= f
+      Lwt_js.sleep 0.2 >>= f
     in
     f ()
 
 
 
 
-let go _ = ignore (
-  catch (fun () ->
-        debug "START !"; fetch_model  "http://www.pdb.org/pdb/files/4IS8.pdb")
+let go _ =
+  ignore (
+    catch begin fun () ->
+      debug "START !";
+      fetch_model  "http://www.pdb.org/pdb/files/4IS8.pdb"
+      >>= fun _ ->
+      let pos =
+        Renderer.float32array [|
+          0.; 0.; 0.;
+          0.; 1.; 0.;
+          0.; 0.; 1.;
+          1.; 0.; 0.;
+          0.; 1.; 0.;
+          1.; 0.; 1.;
+          1.; 0.; 0.;
+          0.; 1.; 0.;
+          1.; 0.; 1.;
+        |] in
+      let norm =
+        Renderer.float32array [|
+          0.; 0.; 0.;
+          0.; 1.; 0.;
+          0.; 0.; 1.;
+          1.; 0.; 0.;
+          0.; 1.; 0.;
+          1.; 0.; 1.;
+          1.; 0.; 0.;
+          0.; 1.; 0.;
+          1.; 0.; 1.;
+        |] in
+      Renderer.start (pos, norm)
+    end
     (fun exn -> error "uncaught exception: %s" (Printexc.to_string exn)));
   _true