Browse thread
[Caml-list] Different function on Image format (uses camlImages)
-
chris.danx
- chris.danx
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2003-11-27 (23:54) |
From: | chris.danx <chris.danx@n...> |
Subject: | Re: [Caml-list] Different function on Image format (uses camlImages) |
chris.danx wrote: > 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? Zaps himself!!! I went off on a tangent there. I can tell which format the image is but can't apply rgba_to_gl. The error is File "texload.ml", line 35, characters 45-48: This expression has type Image.rgb = Color.Rgb.t but is here used with type Image.rgba = Color.Rgba.t Line 35 is the [| 4 component array |] in rgba_to_gl. I think I understand why i get this error, I'm just not sure I know how to resolve it (i got it previously, but ripped out the pattern matching code for the image format). It seems the image needs to be treated as OImage.rgba32 but I'm a bit lost... This is the complete script so far... let rgb_to_gl img = let w = img#width and h = img#height in let targ_img = GlPix.create `ubyte ~format:`rgb ~width:w ~height:h in for i = 0 to w - 1 do for j = 0 to h - 1 do let pix = img#get i j in Raw.sets (GlPix.to_raw targ_img) ~pos:(3*i*h+j) [| pix.r; pix.g; pix.b |]; done done; targ_img;; let rgba_to_gl img = let w = img#width and h = img#height in let targ_img = GlPix.create `ubyte ~format:`rgba ~width:w ~height:h in for i = 0 to w - 1 do for j = 0 to h - 1 do let pix = img#get i j in Raw.sets (GlPix.to_raw targ_img) ~pos:(4*i*h+j) [| pix.r; pix.g; pix.b; pix.alpha|]; done done; targ_img;; 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 conv = match img#tag with ClassRgb24 -> rgb_to_gl | ClassRgba32 -> rgba_to_gl in Hashtbl.add texts tex_id (conv img); () end;; let _ = let tex = new texture_loader in tex#load "NeHe.bmp" "bob";; 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