From: Kenny Tilton
Subject: (type-of 1.0f0)
Date: 
Message-ID: <3E4044C7.50508@nyc.rr.com>
(type-of 1.0f0)

LW: double-float
ACL: single-float

OK, I'll live. But then how do I get LW to give me a single-float (if a 
"C" function wants one)?

(coerce 1.0f0 'single-float)? Interestingly, in the LW listener it just 
says "1.0". I was hoping it would do something readably back.

Is there another alpha char like f or d which requires an implementation 
to give me a single-float? 1.0s0 was accepted but yields a double-float.

-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore

From: Paul F. Dietz
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <uJadnSqyR9qi_t2jXTWc3A@dls.net>
Kenny Tilton wrote:

> OK, I'll live. But then how do I get LW to give me a single-float (if a 
> "C" function wants one)?

CL implementations are allowed to collapse some or all of the
float hierarchy (subject to some constraints).  See the hyperspec for
details.

	Paul
From: Kenny Tilton
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <3E40C9E9.50606@nyc.rr.com>
Paul F. Dietz wrote:
> Kenny Tilton wrote:
> 
>> OK, I'll live. But then how do I get LW to give me a single-float (if 
>> a "C" function wants one)?
> 
> 
> CL implementations are allowed to collapse some or all of the
> float hierarchy (subject to some constraints).  See the hyperspec for
> details.

The Hyperspec doesn't really help; I am dealing with the world outside 
Lisp, OpenGL via FFIs. I have to talk C to C. But, fine, I am hearing 
that 'coerce is the only way out. I'll live. :)

The background is that Cello code which talks to OpenGL works from ACL 
but not from LW. This /could/ be an FFI difference I am not handling 
properly, but right now it looks as if LW parsing 1.0f0 as a double is 
Suspect #1.

I posted here because I could not come up with a 1.0?0 which produced 
single-floats under LW. I guess there is no ? Helloooo, coerce.


-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore
From: Raymond Wiker
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <86of5rgh7q.fsf@raw.grenland.fast.no>
Kenny Tilton <·······@nyc.rr.com> writes:

> I posted here because I could not come up with a 1.0?0 which produced
> single-floats under LW. I guess there is no ? Helloooo, coerce.

        Did you try 1.0s0?

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/
From: Kenny Tilton
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <3E413B82.2000402@nyc.rr.com>
Raymond Wiker wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> 
>>I posted here because I could not come up with a 1.0?0 which produced
>>single-floats under LW. I guess there is no ? Helloooo, coerce.
> 
> 
>         Did you try 1.0s0?

Yeah, returned a double. :( Here's some more playing inspired by private 
mail help:

> CL-USER 1 > (type-of (coerce 1.0 'single-float))
> DOUBLE-FLOAT
> 
> CL-USER 2 > *read-default-float-format*
> SINGLE-FLOAT
> 
> CL-USER 3 > (read-from-string "1.0")
> 1.0
> 3
> 
> CL-USER 4 > (type-of *)
> DOUBLE-FLOAT
> 
> CL-USER 5 > (read-from-string "1.0e0")
> 1.0
> 5
> 
> CL-USER 6 > (type-of *)
> DOUBLE-FLOAT
> 
> CL-USER 7 > 

As one rescuer guessed, the coerce was a no-op, LW does not do 
double-floats outside arrays. (Someone suggested single-float arrays 
were as far as i could get.) Mo better playing:

> CL-USER 7 > (setq *aa* (make-array 5 :element-type 'single-float :initial-element 2))
> 
> Error: Attempt to set single-float array element to 2 of type FIXNUM.

> CL-USER 13 > (setq *aa* (make-array 5 :element-type 'single-float :initial-element 2.0s0))
> #(2.0 2.0 2.0 2.0 2.0)
> 
> CL-USER 14 > (type-of (aref *aa* 0))
> DOUBLE-FLOAT

Looks like the FFI is my only friend. I may have missed something in 
this regard. Early on I screwed things up (under ACL) by typing 1.0d0 
where a C float was wanted. That was just dumb, but at the same time I 
was surprised that my FF definition of the C function (which /did/ 
specify float) did not save me. I changed the literal to 1.0f0 and all 
was well.

Now I am thinking I need to go back to school on FFIs in general, which 
brings me to:

Nils Goesche wrote:
 > If double-floats are all you have you call the C functions
 > with ... double-floats, what else?  For this to work you have to make
 > sure that you declare your C functions properly, for example:
 >
 > (fli:define-foreign-function (foo "foo" :source)
 >     ((x :float))
 >   :result-type :float
 >   :language :ansi-c)
 >
 > The :language :ansi-c bit is essential here...

I'll give it a try, sounds promising. I also see that I could define the 
type of the argument to be :lisp-single-float. Specifying the :language 
seems a little easier. Gotta hack UFFI, though, to get that in there.

Thx for the help, everyone, here and in the mail.

-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore
From: Matthew Danish
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <20030205201632.A27643@lain.cheme.cmu.edu>
On Wed, Feb 05, 2003 at 04:23:07PM +0000, Kenny Tilton wrote:
> Nils Goesche wrote:
>  > If double-floats are all you have you call the C functions
>  > with ... double-floats, what else?  For this to work you have to make
>  > sure that you declare your C functions properly, for example:
>  >
>  > (fli:define-foreign-function (foo "foo" :source)
>  >     ((x :float))
>  >   :result-type :float
>  >   :language :ansi-c)
>  >
>  > The :language :ansi-c bit is essential here...
> 
> I'll give it a try, sounds promising. I also see that I could define the 
> type of the argument to be :lisp-single-float. Specifying the :language 
> seems a little easier. Gotta hack UFFI, though, to get that in there.

Well, with CL-SDL, the 2D examples work in LWW but the OpenGL stuff
usually displays a blank screen.  An interesting exception is the
:solar-system demo which displays the "sun" and what appears to be some
planets flickering at two different spots on the screen, as if they were
teleporting between those two locations.  (What they really should be
doing is proceeding in a nice circle around the center).  I presume this
is due to some float borkage.  I am using :float (which LWW defines as
equivalent to :lisp-single-float) and using OpenGL single-float
operations (where available).  I tried adding :language :ansi-c to UFFI,
but that didn't change anything.  UFFI also adds :calling-convention
:cdecl, which appears to be correct.

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Nils Goesche
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <87wukep2xu.fsf@darkstar.cartan>
Matthew Danish <·······@andrew.cmu.edu> writes:

> On Wed, Feb 05, 2003 at 04:23:07PM +0000, Kenny Tilton wrote:
> > Nils Goesche wrote:
> >  > If double-floats are all you have you call the C functions
> >  > with ... double-floats, what else?  For this to work you have to make
> >  > sure that you declare your C functions properly, for example:
> >  >
> >  > (fli:define-foreign-function (foo "foo" :source)
> >  >     ((x :float))
> >  >   :result-type :float
> >  >   :language :ansi-c)
> >  >
> >  > The :language :ansi-c bit is essential here...
> > 
> > I'll give it a try, sounds promising. I also see that I could
> > define the type of the argument to be
> > :lisp-single-float. Specifying the :language seems a little
> > easier. Gotta hack UFFI, though, to get that in there.
> 
> tried adding :language :ansi-c to UFFI, but that didn't change
> anything.  UFFI also adds :calling-convention :cdecl, which
> appears to be correct.

I lost track of what you are actually trying to do, but whatever
it is, do /not/ omit the :language :ansi-c thing, at least not
for C functions that expect (single) floats...

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Matthew Danish
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <20030205231014.B27643@lain.cheme.cmu.edu>
On Thu, Feb 06, 2003 at 03:18:05AM +0100, Nils Goesche wrote:
> I lost track of what you are actually trying to do, but whatever
> it is, do /not/ omit the :language :ansi-c thing, at least not
> for C functions that expect (single) floats...

Trying to make CL-SDL work on LWW =)

The OpenGL portions are having trouble, and I described the symptoms in
the previous post.  I also modified UFFI to properly use :language
:ansi-c but that didn't fix the problem even when I recompiled CL-SDL.

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Kenny Tilton
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <3E41CB60.2010805@nyc.rr.com>
Nils Goesche wrote:
> Matthew Danish <·······@andrew.cmu.edu> writes:
> I lost track of what you are actually trying to do, but whatever
> it is, do /not/ omit the :language :ansi-c thing, at least not
> for C functions that expect (single) floats...

I think I did some mislearning in my early FFI days. Thought I had to 
get the types of supplied arguments right, but of course the FFI handles 
that if properly informed about the functions called.

I added a test C function to freeglut, one which takes one parameter for 
each type I have to feed OpenGL, an even dozen. That is working nicely 
now from ACL and LW. GLboolean (unsigned char in C) was the nastiest, 
required some implementation-dependent adjustments.

But OpenGL still is not working from LW for me, and all I am trying to 
do is clear the screen to different glClearColors. Not a lot to ask. I 
actually get noise, sometimes recognizable as if some other window's 
device context is being sucked in (or just a win32 display buffer 
somewhere).

Tomorrow I will start tunneling from the other direction. get LW opengl 
examples working, then see if the way they set up the ogl context is 
different in interesting ways from FreeGluts. I can also continue from 
my end by yanking UFFI and going with LW's own FFI directly (and using 
their definitions for all the OpenGl stuff.

Glad to hear your stuff does not get along well with LW either, in the 
sense that misery loves company. :) But it does sound as if you are 
getting somewhat better results than I. I'll let you know if I have any 
luck, by email unless it turns out to be an interesting FFi issue others 
might care about.

thx for the input.

-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore
From: Rob Warnock
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <gbqdnaFaz9aWtN-jXTWc-w@speakeasy.net>
Kenny Tilton  <·······@nyc.rr.com> wrote:
+---------------
| But OpenGL still is not working from LW for me, and all I am trying to 
| do is clear the screen to different glClearColors. Not a lot to ask. I 
| actually get noise, sometimes recognizable as if some other window's 
| device context is being sucked in (or just a win32 display buffer 
| somewhere).
+---------------

You probably already know all of the following, and if so,
"never mind", but...

You might try doing a "swapbuffers()" [or whatever they call it
in OpenGL these days]. IIRC from my days at SGI (though I was a
networking person, not graphics), the basic IrisGL and OpenGL
rendering models were to render into the "background" frame buffer,
then when you're done with drawing that frame, do a "swapbuffers()"
(or eq.) which -- after delaying until the next vertical retrace! --
flips some address bits in the graphics engine (or card) so that the
foreground & background frame buffers swap roles. [Nota bene: no data
is copied during this operation! Only the identities of "front" and
"back" are swapped.]

Then you start rendering the next frame into the "new" background
buffer, starting with "clear()" and drawing the entire picture again,
then issue a "swapbuffers()", etc. Think of a FORCE-OUTPUT that you
can only call 60 times a second at most. [Well, you can *try* to call
it faster, but it won't return from a call until the next VIR...]


-Rob

-----
Rob Warnock, PP-ASEL-IA		<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Kenny Tilton
Subject: Cello poll results and more
Date: 
Message-ID: <3E4AAB66.8030403@nyc.rr.com>
First, it is a landslide for CMUCL as the next Cello implementation. UPS 
truck (with Knoppix CD) where are you?

Mac OS X was a close second. In either case I would be building atop 
X11, so OS X will likely follow CMU in short order. I kinda like the 
idea of covering the commercial implementations first.

This is going to be a bigger effort, because I think I will dump 
FreeGlut (or translate it to CL) but somehow make it CL all the way 
down. For one thing I can stop worrying about callbacks, for another it 
means native widgets are easier to do if/when I go for that.

So now I just have to master:

- Linux
- Emacs/ILisp
- X11/clx

Yechh. :) Now just to wrap up for those hew, those happy few trying to 
get LW working with OpenGL...

> Kenny Tilton  <·······@nyc.rr.com> wrote:
> +---------------
> | But OpenGL still is not working from LW for me, and all I am trying to 
> | do is clear the screen to different glClearColors. Not a lot to ask. I 
> | actually get noise, sometimes recognizable as if some other window's 
> | device context is being sucked in (or just a win32 display buffer 
> | somewhere).
> +---------------

Unfortunately I went into thousand-monkey mode before making LW my 
bitch, so I do not know how I got Cello working. I do know that ACL is 
more forgiving than LW at FF stuff, so some goofs I got away with under 
ACL had to be corrected under LW, but that's all to the good.

Once all that was working I could only get to OpenGL functions by first 
calling a Glut function which then called OpenGL (which is statically 
linked into FreeGlut). Direct OpenGL calls seemed like NOPs.

Not sure which monkey thought of this, but in the end I stopped loading 
opengl32 (as module "GL"), then changed all the FFI declarations to 
specify module "OPENGL32" or "GLU32", and Cello started working. Not 
sure how that can work without the dll being loaded, because LW's own 
examples do load those modules. So maybe if I built an EXE it would not 
work, but then I would just put in the same loads I see in LW sample 
code and I wager all would be well.

Anyway, it works, which tells me a proper solution (assuming mine is 
flawed) is possible, so I am declaring victory and moving on to a new 
platform.



-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore
From: Nils Goesche
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <87vfzzblvf.fsf@darkstar.cartan>
Kenny Tilton <·······@nyc.rr.com> writes:

> (type-of 1.0f0)
> 
> LW: double-float
> ACL: single-float
> 
> OK, I'll live. But then how do I get LW to give me a
> single-float (if a "C" function wants one)?

SYSMON 69 > (subtypep 'double-float 'single-float)
T
T

:-)

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Kenny Tilton
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <3E40CA93.5000104@nyc.rr.com>
Nils Goesche wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> 
>>(type-of 1.0f0)
>>
>>LW: double-float
>>ACL: single-float
>>
>>OK, I'll live. But then how do I get LW to give me a
>>single-float (if a "C" function wants one)?
> 
> 
> SYSMON 69 > (subtypep 'double-float 'single-float)

Does "C" see things the same way? Is this a big-endian vs. little-endian 
thang?

-- 

  kenny tilton
  clinisys, inc
  http://www.tilton-technology.com/
  ---------------------------------------------------------------
"Cells let us walk, talk, think, make love and realize
  the bath water is cold." -- Lorraine Lee Cudmore
From: Nils Goesche
Subject: Re: (type-of 1.0f0)
Date: 
Message-ID: <lyof5qde92.fsf@cartan.de>
Kenny Tilton <·······@nyc.rr.com> writes:

> Nils Goesche wrote:
> > Kenny Tilton <·······@nyc.rr.com> writes:
> >
> >>(type-of 1.0f0)
> >>
> >>LW: double-float
> >>ACL: single-float
> >>
> >>OK, I'll live. But then how do I get LW to give me a
> >>single-float (if a "C" function wants one)?

> > SYSMON 69 > (subtypep 'double-float 'single-float)

> Does "C" see things the same way? Is this a big-endian
> vs. little-endian thang?

No and no.  If double-floats are all you have you call the C functions
with ... double-floats, what else?  For this to work you have to make
sure that you declare your C functions properly, for example:

(fli:define-foreign-function (foo "foo" :source)
    ((x :float))
  :result-type :float
  :language :ansi-c)

The :language :ansi-c bit is essential here (IIRC, in old K&R C, float
arguments were automatically promoted to double, and they still are
for functions with variadic arguments and functions with absent
argument declarations or some such).  LispWorks already comes with
OpenGL bindings; you might want to have a look at how they work with
GLfloats...

 /usr/local/lib/LispWorks/lib/4-2-0-0/examples/opengl/

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0