From: Maurizio Colucci To: lablgtk at kaba.or.jp Subject: What's wrong with this code? [GlGtk.area] Date: Sat, 14 Aug 2004 15:19:27 +0200 MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200408141519.27667.seguso.forever at tin.it> Hello there! I am trying to write a hello-world program with lablgtk2 and GlGtk.area, but something is going wrong. The following program should display a GtkGlArea with a triangle inside: let _ = let delete_event ev = print_endline "Delete event occurred"; flush stdout; false (* false = quit *) in let destroy () = print_endline "destroy"; GMain.Main.quit () in let locale = GtkMain.Main.init () in let window = GWindow.window () in let _ = window#event#connect#delete ~callback:delete_event in let _ = window#connect#destroy ~callback:destroy in let ar = GlGtk.area [ `RGBA; `DOUBLEBUFFER] ~packing:window#add ~show:true () in let my_opengl_reshape ~width ~height = print_endline "my_opengl_reshape called"; ar#make_current (); GlDraw.viewport 0 0 width height; GlMat.mode `projection; GlMat.load_identity (); GlMat.ortho (0.0, float_of_int width) (float_of_int height, 0.0) (-1.0, 0.0) in let my_opengl_init () = print_endline "my_opengl_init called"; ar#make_current (); GlDraw.shade_model `smooth; GlClear.color (0.1, 0.02, 0.0); Gl.disable `depth_test; Gl.enable `blend; GlFunc.blend_func `src_alpha `one_minus_src_alpha; Gl.enable `alpha_test; Gl.enable `line_smooth; Gl.enable `point_smooth; GlFunc.alpha_func `greater 0.0 in let my_opengl_display () = ar#make_current (); GlClear.clear [`color]; GlDraw.color (1.0, 1.0, 1.0); GlDraw.begins `triangle_strip; GlDraw.vertex2 (10.0, 10.0); GlDraw.vertex2 (10.0, 90.0); GlDraw.vertex2 (90.0, 90.0); GlDraw.ends (); Gl.flush () ; ar#swap_buffers () in let _ = ar#connect#reshape ~callback:my_opengl_reshape in let _ = ar#connect#realize ~callback: my_opengl_init in let _ = ar#connect#display ~callback: my_opengl_display in window#show (); GMain.Main.main () But this only displays an empty window. The gl area is not visible. The output is: debian:/dat/pub/src/by-mau/adventure/src/ocaml# ./test.exe GlGtk-WARNING **: could not make current GlGtk-WARNING **: could not make current GlGtk-WARNING **: could not make current Delete event occurred destroy Apparently the callbacks are not being called. Furthermore, there are problems with make_current. The output stays the same if I omit the call to ar#make_current() I am really stuck. Does the program work on your machine? (I am using debian sid with the nvidia driver) What can the problem be? Thanks for any help. Maurizio