caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] LablGL - get_matrix problem or silly mistake
@ 2005-12-29 18:08 Jonathan Harrop
  0 siblings, 0 replies; only message in thread
From: Jonathan Harrop @ 2005-12-29 18:08 UTC (permalink / raw)
  To: caml-list

On Thu Dec 29 11:54 , 'Grzegorz Malesik' <fnan@wp.pl> sent:  
>I'm using the LablGL 1.0.1 and have a get_matrix related problem. I wonder   
>if it actually works (however I'm just a beginner in ocaml so I may be   
>wrong).  
 
I've been using that lablGL function for quite some time and it seems to work perfectly. I just wrote  
a little test program and that prints the identity matrix as expected:  
  
open Printf;;  
  
let print_mat m =  
  Array.iter (fun row ->  
		Array.iter (printf "%f ") row;  
		printf "\n") (GlMat.to_array m);;  
  
let _ =  
  let argv' = Glut.init Sys.argv in  
  ignore (Glut.createWindow ~title:"OpenGL Demo");  
  Glut.displayFunc ~cb:(fun () ->  
			  GlMat.mode `modelview;  
			  GlMat.load_identity();  
			  print_mat (GlMat.get_matrix `modelview_matrix));  
  Glut.idleFunc ~cb:(Some (fun () -> exit 0));  
  Glut.mainLoop ();; 
 
$ ocamlc -I +lablgl lablglut.cma lablgl.cma base.ml -o base 
$ ./base 
1.000000 0.000000 0.000000 0.000000 
0.000000 1.000000 0.000000 0.000000 
0.000000 0.000000 1.000000 0.000000 
0.000000 0.000000 0.000000 1.000000 
 
So I think your problem is an OpenGL one rather than an OCaml one. 
 
>GlMat.mode `modelview;  
>GlMat.push ();  
>GlMat.load_identity ();  
>let transform_matrix = GlMat.get_matrix `modelview_matrix in  
>print_matrix (transform_matrix);  
  
Check for OpenGL and GLU errors. Have you called "GlMat.push" too many times and run out of matrix  
stack? Are you calling "GlMat.pop" for every push? Should you factor those pairs of calls out into a 
HOF to ensure that they are always called correctly? 
 
>This is the print matrix function:  
>  
>(* outputs the given matrix *)  
>let print_matrix matrix =  
>    let mat = GlMat.to_array(matrix) in  
>    print_string "[";  
>    Array.iter(print_separated_float) mat.(0);  
>    print_string "|\n|";  
>    Array.iter(print_separated_float) mat.(1);  
>    print_string "|\n|";  
>    Array.iter(print_separated_float) mat.(2);  
>    print_string "|\n|";  
>    Array.iter(print_separated_float) mat.(3);  
>    print_string "]\n"  
  
You may also like to use String.concat to avoid the superfluous space at the end of each line in my 
above implementation: 
  
let print_mat = 
  let aux l = String.concat " " (List.map string_of_float l) in 
  Array.iter (fun r -> print_endline (aux (Array.to_list r)));; 
 
Cheers, 
Jon. 
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-12-29 18:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-29 18:08 [Caml-list] LablGL - get_matrix problem or silly mistake Jonathan Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).