Advertisement
Guest User

Untitled

a guest
Sep 28th, 2011
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.54 KB | None | 0 0
  1. let rotate = ref 1.0
  2.  
  3. let _ = Sdl.init [`VIDEO] ; at_exit Sdl.quit
  4.  
  5. let key_handler k = match k with
  6.   | {Sdlevent.keysym=Sdlkey.KEY_ESCAPE} ->
  7.       print_endline "I'll miss you so much..." ;
  8.   | {Sdlevent.keysym=Sdlkey.KEY_SPACE} ->
  9.     print_endline "UP" ;
  10.   | {Sdlevent.keysym=Sdlkey.KEY_DOWN} ->
  11.     print_endline "DOWN";  
  12.   | _ -> ()
  13.  
  14. let renderScene () =
  15.   let current_time = ref (Sdltimer.get_ticks()) in
  16.   GlClear.clear[`color;`depth];
  17.   GlMat.rotate3 (!rotate) (0.0,0.0,1.0);
  18.   GlDraw.begins `quad_strip;
  19.   GlDraw.color (1.0, 0.0, 0.0);
  20.   GlDraw.vertex3 (-0.5, 0.5, 0.0);
  21.   GlDraw.vertex3 (-0.5, -0.5, 0.0);
  22.   GlDraw.color (0.0, 0.0, 1.0);
  23.   GlDraw.vertex3 (0.5, 0.5, 0.0);
  24.   GlDraw.vertex3 (0.5,-0.5, 0.0);
  25.   GlDraw.ends ();
  26.   current_time := Sdltimer.get_ticks() - !current_time;
  27.   if(!current_time < 10) then
  28.     Sdltimer.delay (10 - !current_time);
  29.   Glut.swapBuffers();
  30.   Glut.postRedisplay();
  31.  begin
  32.     match Sdlevent.poll () with
  33.       | Some (Sdlevent.KEYDOWN k) ->
  34.     print_endline "nope"; key_handler k
  35.       | None | _ -> print_endline "nopeee";
  36.   end;
  37.   Gl.flush();;
  38.  
  39.  
  40.  
  41. let () =
  42.   ignore(Glut.init Sys.argv);
  43.   Glut.initDisplayMode ~alpha:true ~double_buffer:true ~depth:true ();
  44.   Glut.initWindowPosition ~x:100 ~y:100;
  45.   Glut.initWindowSize ~w:500 ~h:500;
  46.   ignore(Glut.createWindow ~title:"3DMapPro - Edition Expert Business 2012");
  47.   GlClear.color(1.,1.,1.);
  48.   Glut.displayFunc ~cb:(renderScene);
  49.   print_string "oui";
  50.   Glut.keyboardFunc (fun ~key ~x ~y -> if key=27 then exit 0);
  51.   Glut.mainLoop();;
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement