caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Different function on Image format  (uses camlImages)
@ 2003-11-27 23:27 chris.danx
  2003-11-27 23:55 ` chris.danx
  0 siblings, 1 reply; 3+ messages in thread
From: chris.danx @ 2003-11-27 23:27 UTC (permalink / raw)
  To: Caml Mailing List

Hi,

I'm writing a simple texture loader class so that I can load up images 
using camlimages, convert them to a format suitable for opengl, then 
store them under some name in a hash table.  So far I've got it working 
for rgb24 format images, but ideally I want to use both 24bit rgb pixels 
and 32bit rgba pixels.  The problem is deciding which function to call 
depending on the image type.

Before I go on, is this an appropriate place to ask about CamlImages? 
Also I am new to OCaml, and this is one of the few things I've attempted 
of any complexity.

This is the class as it stands.


class texture_loader
   = object(self)

     val mutable texts = Hashtbl.create 5;

     method load (filename : string) (tex_id : string) =
	try
	  let x = Hashtbl.find texts tex_id in
	    raise (Id_exists tex_id)
	with
	    Not_found ->         	
	      let img = OImage.load filename [] in
		let img = OImage.rgb24 img in
		  Hashtbl.add texts tex_id (rgb_to_gl img);
		  ()
end;;


Assuming I have functions "rgb_to_gl" and "rgba_to_gl", how can I tell 
which format the image is so the correct function can be called. 
Something like this is what sprang to mind

let img = match <image_format> with
      <rgb>  -> OImage.rgb24  img
    | <rgba> -> OImage.rgba24 img
in ...

The problem is what should the things between the angled brackets be?


Thanks,
Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-11-29 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-27 23:27 [Caml-list] Different function on Image format (uses camlImages) chris.danx
2003-11-27 23:55 ` chris.danx
2003-11-29  0:36   ` chris.danx

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).