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
|
(**************************************************************************)
(* Lablgtk - Examples *)
(* *)
(* This code is in the public domain. *)
(* You may freely copy parts of it in your application. *)
(* *)
(**************************************************************************)
(* $Id$ *)
let init () =
List.iter Gl.enable [`line_smooth; `blend];
GlFunc.blend_func ~src:`src_alpha ~dst:`one_minus_src_alpha;
GlMisc.hint `line_smooth `dont_care;
GlDraw.line_width 4.;
GlClear.color (0., 0., 0.)
let rot_angle = ref 0.
let display ~area () =
GlClear.clear [`color];
GlDraw.color (0., 1., 0.);
GlMat.push ();
GlMat.rotate ~angle:(-. !rot_angle) ~z:0.1 ();
GlDraw.begins `lines;
GlDraw.vertex2 (-0.5, 0.5);
GlDraw.vertex2 (0.5, -0.5);
GlDraw.ends ();
GlMat.pop ();
GlDraw.color (0., 0., 1.);
GlMat.push ();
GlMat.rotate ~angle:(!rot_angle) ~z:0.1 ();
GlDraw.begins `lines;
GlDraw.vertex2 (0.5, 0.5);
GlDraw.vertex2 (-0.5, -0.5);
GlDraw.ends ();
GlMat.pop ();
Gl.flush ();
area#swap_buffers ()
let reshape ~width:w ~height:h =
GlDraw.viewport ~x:0 ~y:0 ~w ~h;
GlMat.mode `projection;
GlMat.load_identity();
if w < h then
GluMat.ortho2d ~x:(-1., 1.) ~y:(-.float w /. float h, float w /. float h)
else
GluMat.ortho2d ~y:(-1., 1.) ~x:(-.float w /. float h, float w /. float h);
GlMat.mode `modelview;
GlMat.load_identity()
open GdkKeysyms
let main () =
let w = GWindow.window ~title:"Antialiasing/Gtk" () in
w#connect#destroy ~callback:GMain.quit;
let area =
GlGtk.area [`RGBA;`DOUBLEBUFFER]
~width:500 ~height:500 ~packing:w#add () in
area#connect#realize ~callback:init;
area#connect#reshape ~callback:reshape;
area#connect#display ~callback:(display ~area);
w#event#connect#key_press ~callback:
begin fun ev ->
let key = GdkEvent.Key.keyval ev in
if key = _r || key = _R then begin
rot_angle := !rot_angle +. 20.;
if !rot_angle > 360. then rot_angle := 0.;
display ~area ()
end;
true
end;
w#show ();
GMain.main ()
let _ = main ()
|