English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] lablGL and camlimages
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-02-20 (13:48)
From: malc <malc@p...>
Subject: Re: [Caml-list] lablGL and camlimages
On Wed, 20 Feb 2002, Bor-Yuh Evan Chang wrote:

> Hello,
> I am using the lablGL library to use Open GL in OCaml.  I am trying to
> read from the frame buffer (using GlPix.read) and output to a file (a jpeg
> using camlimages), but I am having difficulties.  Has anyone tried this or
> have any pointers to where I can find some additional information?
What kind of difficulties? lablgl or camlimages related? In any case here
goes very simple template to output picture to TGA, you can work from

method screenshot =
  let w = Togl.width togl
  and h = Togl.height togl in
  let pixels = GlPix.read
      ~x:0 ~y:0
      ~width:w ~height:h
      ~format:`rgb ~kind:`ubyte
  let praw = GlPix.to_raw pixels in
  let raw = Raw.gets ~pos:0 ~len:(Raw.byte_size praw) praw in
  let w = GlPix.width pixels in
  let h = GlPix.height pixels in
  let f = open_out_bin "shot.tga" in
  let outb = output_byte f in
  let outw w = output_byte f (w land 0xff); output_byte f (w lsr 8) in
  outw 0;
  outb 2;
  for i = 0 to 8 do outb 0 done;
  outw w; outw h;
  outb 24;
  outb 0;
  for i = 0 to pred (w * h) do
    outb raw.(i * 3 + 2);
    outb raw.(i * 3 + 1);
    outb raw.(i * 3 + 0);
  close_out f


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