about graphics and GUI

Dan Gudmundsson dgud@REDACTED
Tue Sep 19 10:43:10 CEST 2000

Karlsson Mikael writes:
 > This sounds interesting, but I do not understand were the binary 
 > syntax comes in. Is it together with the IC application?
 > Could you give an example?
 > /Mikael
 > > With the new binary syntax it is really easy to write a program that 
 > > does this if the source header file/interface is well written.. 
 > > I wrote one in couple of hours that could generate 75% of the 
 > > opengl functions for example.. 
 > > /Dan

Sure, as I said the opengl api is really nice/easy.
All the used types are simple types so I didn't have poke 
around with structures and complex C types. 

I generated stubs for all the functions into 5 files and 
modified them by hand. For example every function that returns
something (i.e. all glGet* functions) are handwritten, but even
in these functions most of the work is generated and I had to
handle pointers, allocate memory for arrays and such.

For example this declaration in gl.h
GLAPI void GLAPIENTRY glColorMask( GLboolean red, GLboolean green,
			 GLboolean blue, GLboolean alpha  );

Generates the following: 
gl.erl    (the erlang API) 
%% Func:    clearColor 
%% Args:    
%% Returns: 
%% C-API func: void glClearColor(GLclampf red, GLclampf green, 
%%                               GLclampf blue, GLclampf alpha)
clearColor(Red, Green, Blue, Alpha) -> 
    cast(?glClearColor, <<Red:32/float, Green:32/float, Blue:32/float, 

esdl_gl.c (the c-wrapper function)
int egl_clearColor (int len, char * buff) 
 char * bp; 
 GLclampf red;
 GLclampf green;
 GLclampf blue;
 GLclampf alpha;
 bp = ARGS(buff);
 red = getFloat32be(bp);
 green = getFloat32be(bp);
 blue = getFloat32be(bp);
 alpha = getFloat32be(bp);
 glClearColor(red, green, blue, alpha);
 return 0;

sdl_wrapper.c   (cases for a big switch with every supported function)
   case glClearColorFunc:
      egl_clearColor(len, buff);

And function definitions in .h and .hrl files for the macros..

The main loop in the C-program read packages from stdin 
calls the wrapper function, which calls the library function
and then (if any) writes the result on stdout.

read_packet and write_packet is copied from the erlang book.
Then I have the macros get8/put8() put32be()/get32be()...
to convert values on the C side to the appropriate types...
(copied from the erl_interface src)


More information about the erlang-questions mailing list