Re: [Haskell-cafe] Re: Wrapping FTGL in FFI calls

2008-06-20 Thread Jefferson Heard
Well, Achim you were almost exactly correct.  I have a functional function
interface in about half an hour's worth of work.  I have one question, which
is how to create a Ptr to four CFloats on the fly, pass them to the bounding
box functions, and then come back out with a [Float]

My prototype looks like this:
foreign import ccall unsafe ftglGetFontBBox fgetFontBBox :: Font -
CString - Ptr CFloat - IO ()

the ptr to cfloat should be a float[4], which is modified inside the
original C function.

On Fri, Jun 20, 2008 at 1:16 AM, Achim Schneider [EMAIL PROTECTED] wrote:

 Jefferson Heard [EMAIL PROTECTED] wrote:

  I've been looking for awhile now for a simple way to get truetype
  fonts into my visualizations so I can abandon the hideous GLUT fonts
  and make things that look like they were developed in the 1990s
  instead of back in the days of TRON.  I found FTGL, but I'm mostly a
  Haskell developer these days, and resent having to go back to C just
  to write a simple application.
 
  So I was wondering if anyone had ever wrapped the FTGL library in
  Haskel FFI or whether those out there who are experts on the FFI
  think at first glance it should be readily wrappable by a rank
  amateur at FFI such as myself.
 
  http://ftgl.sourceforge.net/docs/html/
 
 Using the FFI is generally straight forward, as long as you can live
 with using the IO monad and the C code uses objects (well,
 pointers to structs passed as first argument, where's the
 difference...).

 Things only depend on the purity of the C code and how high-level you
 want your interface to be. In this case, I estimate half an hour if
 you're a fast typist. That includes the time needed to read the FFI
 docs.

 --
 (c) this sig last receiving data processing entity. Inspect headers for
 past copyright information. All rights reserved. Unauthorised copying,
 hiring, renting, public performance and/or broadcasting of this
 signature prohibited.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
I try to take things like a crow; war and chaos don't always ruin a picnic,
they just mean you have to be careful what you swallow.

-- Jessica Edwards
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wrapping FTGL in FFI calls

2008-06-20 Thread Jefferson Heard
Oh, and I should say the function I want to implement is

getFontBBox :: Font - String - IO [Float]

I do know how to marhsal/unmarshal the String.  Just not the CFloat array to
Haskell [Float]

On Fri, Jun 20, 2008 at 2:25 PM, Jefferson Heard 
[EMAIL PROTECTED] wrote:

 Well, Achim you were almost exactly correct.  I have a functional function
 interface in about half an hour's worth of work.  I have one question, which
 is how to create a Ptr to four CFloats on the fly, pass them to the bounding
 box functions, and then come back out with a [Float]

 My prototype looks like this:
 foreign import ccall unsafe ftglGetFontBBox fgetFontBBox :: Font -
 CString - Ptr CFloat - IO ()

 the ptr to cfloat should be a float[4], which is modified inside the
 original C function.


 On Fri, Jun 20, 2008 at 1:16 AM, Achim Schneider [EMAIL PROTECTED] wrote:

 Jefferson Heard [EMAIL PROTECTED] wrote:

  I've been looking for awhile now for a simple way to get truetype
  fonts into my visualizations so I can abandon the hideous GLUT fonts
  and make things that look like they were developed in the 1990s
  instead of back in the days of TRON.  I found FTGL, but I'm mostly a
  Haskell developer these days, and resent having to go back to C just
  to write a simple application.
 
  So I was wondering if anyone had ever wrapped the FTGL library in
  Haskel FFI or whether those out there who are experts on the FFI
  think at first glance it should be readily wrappable by a rank
  amateur at FFI such as myself.
 
  http://ftgl.sourceforge.net/docs/html/
 
 Using the FFI is generally straight forward, as long as you can live
 with using the IO monad and the C code uses objects (well,
 pointers to structs passed as first argument, where's the
 difference...).

 Things only depend on the purity of the C code and how high-level you
 want your interface to be. In this case, I estimate half an hour if
 you're a fast typist. That includes the time needed to read the FFI
 docs.

 --
 (c) this sig last receiving data processing entity. Inspect headers for
 past copyright information. All rights reserved. Unauthorised copying,
 hiring, renting, public performance and/or broadcasting of this
 signature prohibited.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




 --
 I try to take things like a crow; war and chaos don't always ruin a picnic,
 they just mean you have to be careful what you swallow.

 -- Jessica Edwards




-- 
I try to take things like a crow; war and chaos don't always ruin a picnic,
they just mean you have to be careful what you swallow.

-- Jessica Edwards
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wrapping FTGL in FFI calls

2008-06-20 Thread Jules Bean

Jefferson Heard wrote:

Oh, and I should say the function I want to implement is

getFontBBox :: Font - String - IO [Float]

I do know how to marhsal/unmarshal the String.  Just not the CFloat 
array to Haskell [Float]


import Foreign.C
import Foreign.Ptr
import Foreign.Marshal.Array

import Control.Applicative(($))

oneway :: Ptr CFloat - IO [Float]
oneway p = map real2Frac $ peekArray 4 p

the other way you would probably want withArray, but I think this is the 
way you need?



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wrapping FTGL in FFI calls

2008-06-20 Thread Jefferson Heard
Exactly.  thanks!

On Fri, Jun 20, 2008 at 4:26 PM, Jules Bean [EMAIL PROTECTED] wrote:

 Jefferson Heard wrote:

 Oh, and I should say the function I want to implement is

 getFontBBox :: Font - String - IO [Float]

 I do know how to marhsal/unmarshal the String.  Just not the CFloat array
 to Haskell [Float]


 import Foreign.C
 import Foreign.Ptr
 import Foreign.Marshal.Array

 import Control.Applicative(($))

 oneway :: Ptr CFloat - IO [Float]
 oneway p = map real2Frac $ peekArray 4 p

 the other way you would probably want withArray, but I think this is the
 way you need?





-- 
I try to take things like a crow; war and chaos don't always ruin a picnic,
they just mean you have to be careful what you swallow.

-- Jessica Edwards
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Wrapping FTGL in FFI calls

2008-06-20 Thread Jules Bean

Sorry, it's realToFrac. Typo!

Jefferson Heard wrote:

Exactly.  thanks!

On Fri, Jun 20, 2008 at 4:26 PM, Jules Bean [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


Jefferson Heard wrote:

Oh, and I should say the function I want to implement is

getFontBBox :: Font - String - IO [Float]

I do know how to marhsal/unmarshal the String.  Just not the
CFloat array to Haskell [Float]


import Foreign.C
import Foreign.Ptr
import Foreign.Marshal.Array

import Control.Applicative(($))

oneway :: Ptr CFloat - IO [Float]
oneway p = map real2Frac $ peekArray 4 p

the other way you would probably want withArray, but I think this is
the way you need?





--
I try to take things like a crow; war and chaos don't always ruin a 
picnic, they just mean you have to be careful what you swallow.


-- Jessica Edwards




___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Wrapping FTGL in FFI calls

2008-06-19 Thread Achim Schneider
Jefferson Heard [EMAIL PROTECTED] wrote:

 I've been looking for awhile now for a simple way to get truetype
 fonts into my visualizations so I can abandon the hideous GLUT fonts
 and make things that look like they were developed in the 1990s
 instead of back in the days of TRON.  I found FTGL, but I'm mostly a
 Haskell developer these days, and resent having to go back to C just
 to write a simple application.
 
 So I was wondering if anyone had ever wrapped the FTGL library in
 Haskel FFI or whether those out there who are experts on the FFI
 think at first glance it should be readily wrappable by a rank
 amateur at FFI such as myself.
 
 http://ftgl.sourceforge.net/docs/html/
 
Using the FFI is generally straight forward, as long as you can live
with using the IO monad and the C code uses objects (well,
pointers to structs passed as first argument, where's the
difference...).

Things only depend on the purity of the C code and how high-level you
want your interface to be. In this case, I estimate half an hour if
you're a fast typist. That includes the time needed to read the FFI
docs.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe