Board index » delphi » glMultMatrix

glMultMatrix

I found the translation of the OpenGL header a bit sloppy :

procedure glMultMatrix(m:PGLFloat); ...

where m is a pointer to a float.
OpenGL expects a matrix there, sort of, rather an array :

var m:array[1..16] of GLFloat;

with vertical ordering.

It's use therefore is :

 glMultMatrix(PGLFloat(@m));

While it works, it kinda looks unclean. Is there another reason,
than just not having time, that it is as it is ?

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

 

Re:glMultMatrix


Quote
"Rene Tschaggelar" <tschagge...@access.ch> wrote in message

news:389745E1.5D6722B8@access.ch...

Quote
>where m is a pointer to a float.
>OpenGL expects a matrix there, sort of, rather an array :

>var m:array[1..16] of GLFloat;

>with vertical ordering.

The vertical ordering is a bit of a surprise.  This sounds like
some sort of Fortran artifact, since that's the memory
ordering used in Fortran.  (FWIW, The Intel Math Library
 has the same "problem.")

Quote
>  glMultMatrix(PGLFloat(@m));

> While it works, it kinda looks unclean. Is there another reason,
> than just not having time, that it is as it is ?

My guess is that this was a quick approach to translating
the interface from C to Delphi, since C does this all the time.

A "char*" in C is used for strings.  You can't really tell if
the pointer is to a single character, or if it's a pointer to a
string of characters, which are null terminated.  There no
way to write this difference in C.

So in C, a pointer to a single float, or a pointer to an array of
floats also has the same construct.  This type of imprecision
in the language has driven me nuts in reverese-engineering
C code, since it's hard to know what the real intent is
sometimes.

--
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:glMultMatrix


 I could think of another reason why it is defined as it is:

Usually an application doesn't know beforehand, how large the array will
be. Thus the most flexible way is to use dynamic allocation:

var pfloats: PGLFloat

   GetMem(pfloats, n*sizeof(GLFloat)) ;

  then pfloats is exactly what is needed:

     glMultMatrix(pfloats);

the nice thing about Delphi (since D3, I think) is that

    pfloats[10]

is the same as

   pfloats^[10].

Thus Delphi has adapted to c-style of treating pointers and arrays
equal.

KH Brenner

Rene Tschaggelar schrieb:

Quote
> I found the translation of the OpenGL header a bit sloppy :

> procedure glMultMatrix(m:PGLFloat); ...

> where m is a pointer to a float.
> OpenGL expects a matrix there, sort of, rather an array :

> var m:array[1..16] of GLFloat;

> with vertical ordering.

> It's use therefore is :

>  glMultMatrix(PGLFloat(@m));

> While it works, it kinda looks unclean. Is there another reason,
> than just not having time, that it is as it is ?

> Rene
> --
> Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Re:glMultMatrix


I forgot to mention that PGLFloat would have to be defined like this

 TGLArray = array[0..0] of GLFloat ;
 PGLFloat = ^TGLArray ;

in order to work as I wrote.

Unfortunatly it is defined as ^GLFloat. Thus a typecast is still needed.

KH Brenner

Other Threads