Board index » delphi » Why glEdgeFlag doesn't work in D4

Why glEdgeFlag doesn't work in D4

Yes, I have found that annoying too. I see no reason why your declarations
should not work. The problem happens where OpenGL.Pas uses GL_TRUE = 1 etc.
That sets up GL_TRUE etc. as integers!

Better would have been GL_TRUE = BYTEBOOL(1); GL_FALSE = BYTEBOOL(0);

Then we would not have to typecast. Just in case, you might want to use
these declarations.

Jon
http://home1.gte.net/jqjacobs/index.htm

Quote
>Investigating the above problem I noticed that in OpenGL.pas (borland's
>version)

>type
>GLboolean = BYTEBOOL;

>const
>GL_TRUE = 1;
>GL_FALSE = 0;

>and glEdgeFlag takes a GLboolean parameter, thus.

>procedure glEdgeFlag (flag: GLboolean); stdcall;

>The effect of this is

>a) glEdgeFlag cannot take GL_TRUE or GL_FALSE as a parameter without a
>typecast (bizarre)
>b) if you pass true to glEdgeFlag then the compiler will push $FF - not $01
>as I would have expected.
>(I think this is because BYTEBOOL is not a clone of Boolean = it is a VB
>type boolean i.e true = -1) This
>causes glEdgeFlag to fail to operate properly.

>To get around this you can call

>glEdgeFlag(Boolean(GL_TRUE))

>but that seems genuinely daft to me.

>In GL.H GLboolean is a UCHAR so I would have thought it is so obvious that
>the Delphi version should be a standard boolean, that there must be some
>compelling reason why it is not. Can anyone think of one?

>As a test I have changed my OpenGL.pas as follows:

>GLboolean = boolean;

>GL_FALSE = false;
>GL_TRUE = true;

>glEdgeFlag now works correctly, but am I going to get bitten elsewhere?

 

Re:Why glEdgeFlag doesn't work in D4


Investigating the above problem I noticed that in OpenGL.pas (borland's
version)

type
GLboolean = BYTEBOOL;

const
GL_TRUE = 1;
GL_FALSE = 0;

and glEdgeFlag takes a GLboolean parameter, thus.

procedure glEdgeFlag (flag: GLboolean); stdcall;

The effect of this is

a) glEdgeFlag cannot take GL_TRUE or GL_FALSE as a parameter without a
typecast (bizarre)
b) if you pass true to glEdgeFlag then the compiler will push $FF - not $01
as I would have expected.
(I think this is because BYTEBOOL is not a clone of Boolean = it is a VB
type boolean i.e true = -1) This
causes glEdgeFlag to fail to operate properly.

To get around this you can call

glEdgeFlag(Boolean(GL_TRUE))

but that seems genuinely daft to me.

In GL.H GLboolean is a UCHAR so I would have thought it is so obvious that
the Delphi version should be a standard boolean, that there must be some
compelling reason why it is not. Can anyone think of one?

As a test I have changed my OpenGL.pas as follows:

GLboolean = boolean;

GL_FALSE = false;
GL_TRUE = true;

glEdgeFlag now works correctly, but am I going to get bitten elsewhere?

regards,

Martin.

Re:Why glEdgeFlag doesn't work in D4


Jon,
I suppose I don't really understand why the translator used BYTEBOOL at all.
I can't imagine that any part of OpenGL expects or requires a boolean with
an ordinal of $FF when true...

Quote
Jon Jacobs <jqjac...@gte.net> wrote in message

news:7uia60$ljp6@forums.borland.com...
Quote
> Yes, I have found that annoying too. I see no reason why your declarations
> should not work. The problem happens where OpenGL.Pas uses GL_TRUE = 1
etc.
> That sets up GL_TRUE etc. as integers!

> Better would have been GL_TRUE = BYTEBOOL(1); GL_FALSE = BYTEBOOL(0);

Re:Why glEdgeFlag doesn't work in D4


Quote
>I can't imagine that any part of OpenGL expects or requires a boolean with
>an ordinal of $FF when true...

Agreed.

// case 1
const
  GL_FALSE=false;
  GL_TRUE=true;
type
  BYTEBOOL=boolean;

or

// case 2
const
  GL_FALSE=BYTEBOOL(0);
  GL_TRUE=BYTEBOOL(1);

both satisfy the requirement that using the symbols always passes a byte
with ordinal value of 0 or 1, whereas:

// case 3
const
  GL_FALSE=0;
  GL_TRUE=1;

does not.

Case 2 more closely matches the C headers it came from, Case 1 is easier and
more natural for a Delphi programmer, but case 3 (IMO) is just a mistake.

Jon
http://home1.gte.net/jqjacobs/index.htm

Re:Why glEdgeFlag doesn't work in D4


Pardon me Jon,
but did you not write the book on OpenGL for Delphi?
I am finding it a most interesting and easy to use book as in introduction
to the world of OpenGL.
Thanks a lot, your time was well spent writing it.
--
Pierre Roux
e pie...@smartnet.co.za
c +27 82 899 4166
t +27 12 661 1303

Jon Q. Jacobs <jqjac...@gte.net> wrote in message
news:7uiok9$odr21@forums.borland.com...

Quote
> >I can't imagine that any part of OpenGL expects or requires a boolean
with
> >an ordinal of $FF when true...

> Agreed.

> // case 1
> const
>   GL_FALSE=false;
>   GL_TRUE=true;
> type
>   BYTEBOOL=boolean;

> or

> // case 2
> const
>   GL_FALSE=BYTEBOOL(0);
>   GL_TRUE=BYTEBOOL(1);

> both satisfy the requirement that using the symbols always passes a byte
> with ordinal value of 0 or 1, whereas:

> // case 3
> const
>   GL_FALSE=0;
>   GL_TRUE=1;

> does not.

> Case 2 more closely matches the C headers it came from, Case 1 is easier
and
> more natural for a Delphi programmer, but case 3 (IMO) is just a mistake.

> Jon
> http://home1.gte.net/jqjacobs/index.htm

Re:Why glEdgeFlag doesn't work in D4


Quote
>Pardon me Jon,
>but did you not write the book on OpenGL for Delphi?
>I am finding it a most interesting and easy to use book as in introduction
>to the world of OpenGL.
>Thanks a lot, your time was well spent writing it.
>--
>Pierre Roux

Thank you for your kind words. It was a lot of hard work, but it was a labor
of love.

Jon

Other Threads