Re: [ooc-compiler] C interface problems
Brought to you by:
mva
|
From: August <fus...@te...> - 2004-11-05 01:13:09
|
Hello Stewart,
Yes, it worked! Thank you. (Not so obvious to use Pascal calling
convention with a C library).
I also skimmed through your GL.Mod file and noticed that literal
values are defined for (macro) constants. Isn't it possible for the
OOC compiler to get the values from the C header file? Moreover I tend
to dislike all but the absolutely necessary Oberon-2 extensions*, so I
would prefer to rename all identifiers to valid Oberon-2 identifiers
(no underscores) that follows the standard naming scheme and keep the
definitions in three different modules: GL.Mod, Glu.Mod and Glut.Mod.
The conversion rules are very regular (thanks to the regularity of the
OpenGL interface):
Constants - Remove the prefix, lower case the first word, capitalize
the following words (if any) and remove the underscores, e.g.
GL_COLOR_BUFFER_BIT becomes colorBufferBit. There also exists a
tradition to use Pascal case (rather than camel case) with exported
variables and constants. Have not decided which is the best choice.
Types - Remove the prefix and capitalize, e.g. GLclampf becomes
Clampf.
Variables - (No exported variables, right?)
Functions - Just remove the prefix, e.g. glutSwapBuffers becomes
SwapBuffers.
-- August
*If we want Oberon-2 with lots of extensions then we might as well
turn to Eiffel.
----- Original Message -----
From: "Stewart Greenhill" <sgr...@ii...>
To: "August" <fus...@te...>
Cc: <ooc...@li...>
Sent: Thursday, November 04, 2004 1:20 PM
Subject: Re: [ooc-compiler] C interface problems
> Hi August,
>
>> One potential problem: the glut functions are defined as
>> "APIENTRY", which under Windows means that they use the "stdcall"
>> calling convention rather than "cdecl". Therefore, you should
>> probably specify "Pascal" rather than "C" as your interface type.
>> That is:
>> MODULE Glut [INTERFACE "Pascal"; LINK LIB "glut32"; LIB
>> "opengl32"; END];
>> I think the same goes for the other GL modules. Presuming that the
>> linker knows the procedure attributes, that may be why it is giving
>> the error (ie. the procedure name matches, but the attributes are
>> wrong).
>
> I ran a quick check, and it looks like this is indeed what happens.
> The following should compile and link fine. It also runs OK, opening
> a window and correctly calling the display procedure.
>
> MODULE Test;
> IMPORT C, Glut;
> VAR w: C.int;
> PROCEDURE Display ["Pascal"];
> END Display;
> BEGIN
> w := Glut.CreateWindow("OpenGL Test");
> Glut.DisplayFunc(Display);
> Glut.MainLoop
> END Test.
>
> MODULE Glut [INTERFACE "Pascal"; LINK LIB "glut32"; LIB "opengl32";
> END];
> IMPORT C;
> TYPE
> DisplayCallback = PROCEDURE;
>
> PROCEDURE ["glutCreateWindow"] CreateWindow*(title: ARRAY OF
> C.char): C.int;
> PROCEDURE ["glutDisplayFunc"] DisplayFunc*(p: DisplayCallback);
> PROCEDURE ["glutMainLoop"] MainLoop*;
> END Glut.
>
> Hope this helps.
>
> Cheers,
> Stewart
>
|