Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] LablGL - get_matrix problem or silly mistake
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jonathan Harrop <jdh30@j...>
Subject: Re: [Caml-list] LablGL - get_matrix problem or silly mistake
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.