From: "David Simmons" References: Subject: Re: OpenGL Example and float problem Date: Sat, 16 Nov 2002 17:09:03 -0800 Lines: 66 Organization: SmallScript Corp X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: Newsgroups: comp.lang.smallscript Path: minos.QKS.COM Xref: minos.QKS.COM comp.lang.smallscript:2156 NNTP-Posting-Host: mail.smallscript.llc 207.213.215.173 "Chris Double" wrote in message news:usmy1m39d.fsf@double.co.nz... > I threw together an example of using OpenGL in SmallScript. It's > available at: > > http://www.double.co.nz/smallscript/OpenGLExample.zip > > For some reason passing floats to an FFI function don't seem to > work. Is there a problem there? For example, in the OpenGL example I > have code like: > > glColor3ub(255, 0, 0). > glVertex2i(0, 1). > > If I replace 'glColor3ub' with 'glColor3f' or 'glColor3d' then the > example doesn't work. eg: > > glColor3f(1.0, 0, 0). > > (When using floats the range is from -1 to 1.0. When using unsigned > byte (ub) the range is 0 to 255). > > No error occurs, it's just the function seems to silently fail. The "auto-marshalling" cannot determine how to pass floats without a hint. So it is not passing the floats correctly. I.e., it does not know if they should be passed in a register, as a pointer, etc. By default it will pass them by reference as , but you really want them passed by-value as . So you have to explicitly override the auto-marshaller's default. You need to provide a hint, as follows: "" Presuming you have the OpenGL dll wrappered as follows: Namespace name: OpenGL dll: OpenGL { "" Declare an extern prototype to hint how values "" should be marshalled. Function [<$extern> glColor3f(<~double>a, <~double> b, <~double> c) ] } Where "~" says ignore the type information for the purposes of multi-method binding (this just makes it a little faster), and the "double" says how the value should be marshalled. Where is a pseudonym for which is a pseudonym for . You can see the actual marshaller code in the methods for #ffiMarshallToFFV, and #ffiMarshallFromFFV. For reference to additional details on float operations, see the c.l.s# discussions "Re: Float Arrays: FFI and memory layout" from "Feb-2002" which I had with Jaco van der Merwe . -- Dave S. [www.smallscript.org] > > I've also done an example using the WildTangent game library [1]. This > tests my IDL generator code. But this library uses floats and those > functions also silently fail. > > [1] http://www.wildtangent.com/ > > Chris. > -- > http://www.double.co.nz/smallscript