Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 31st, 2005, 01:35 PM
Manuel
Guest
 
Posts: n/a
Default Difference between "float" and "GLfloat" ?

Anyone know why for openGL applications must be used GLfloat (and GLint,
etc...) instead float, int, etc..?

thx,

Manuel
  #2  
Old December 31st, 2005, 01:45 PM
W Marsh
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

Manuel wrote:[color=blue]
> Anyone know why for openGL applications must be used GLfloat (and GLint,
> etc...) instead float, int, etc..?
>
> thx,
>
> Manuel[/color]

Portability. The GL Red Book says:

"Implementations of OpenGL have leeway in selecting which C data type to
use to represent OpenGL data types. If you resolutely use the OpenGL
defined data types throughout your application, you will avoid
mismatched types when porting your code between different implementations."
  #3  
Old December 31st, 2005, 02:15 PM
Manuel
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

W Marsh wrote:
[color=blue]
> Portability. The GL Red Book says:
>
> "Implementations of OpenGL have leeway in selecting which C data type to
> use to represent OpenGL data types. If you resolutely use the OpenGL
> defined data types throughout your application, you will avoid
> mismatched types when porting your code between different implementations."[/color]


Thanks.
But this is a problem with C++ too?
If I declare an "int" under windows, maybe different from an "int" under
linux or OSX ?


Regards,

Manuel
  #4  
Old December 31st, 2005, 02:25 PM
W Marsh
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

Manuel wrote:[color=blue]
> W Marsh wrote:
>[color=green]
>> Portability. The GL Red Book says:
>>
>> "Implementations of OpenGL have leeway in selecting which C data type
>> to use to represent OpenGL data types. If you resolutely use the
>> OpenGL defined data types throughout your application, you will avoid
>> mismatched types when porting your code between different
>> implementations."[/color]
>
>
>
> Thanks.
> But this is a problem with C++ too?
> If I declare an "int" under windows, maybe different from an "int" under
> linux or OSX ?
>
>
> Regards,
>
> Manuel[/color]

It may be. Even a char can have more than 8-bits.
  #5  
Old December 31st, 2005, 02:45 PM
Gavin Deane
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?


Manuel wrote:
[color=blue]
> W Marsh wrote:
>[color=green]
> > Portability. The GL Red Book says:
> >
> > "Implementations of OpenGL have leeway in selecting which C data type to
> > use to represent OpenGL data types. If you resolutely use the OpenGL
> > defined data types throughout your application, you will avoid
> > mismatched types when porting your code between different implementations."[/color]
>
>
> Thanks.
> But this is a problem with C++ too?
> If I declare an "int" under windows, maybe different from an "int" under
> linux or OSX ?[/color]

Yes. There is no requirement for an int to be the same size on every
platform.

sizeof returns a number of bytes. You are guaranteed that

sizeof char == 1
sizeof char <= sizeof short <= sizeof int <= sizeof long
CHAR_BIT >= 8

where CHAR_BIT, available by including the <climits> or <limits.h>
header, is the number of bits in a char (i.e. in a byte).

I believe there are also some *minimum* size guarantees for the
integral types. I'm not sure what they are, or whether they are
specified as a number of bits, a number of bytes, or a range of values
that must be accomodated.

Gavin Deane

  #6  
Old December 31st, 2005, 03:05 PM
Ron Natalie
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

Manuel wrote:[color=blue]
> W Marsh wrote:
>[color=green]
>> Portability. The GL Red Book says:
>>
>> "Implementations of OpenGL have leeway in selecting which C data type
>> to use to represent OpenGL data types. If you resolutely use the
>> OpenGL defined data types throughout your application, you will avoid
>> mismatched types when porting your code between different
>> implementations."[/color]
>
>
> Thanks.
> But this is a problem with C++ too?
> If I declare an "int" under windows, maybe different from an "int" under
> linux or OSX ?[/color]

Yes. This is why there are typedefs in the various API's that use C
and C++ to nail this down on a particular implementation. Even in
the standard language we have things like size_t.

The later version of the C standard even includes some "predefined"
typedefs that assign traits to various integer types for example.
  #7  
Old January 1st, 2006, 05:45 AM
Jack Klein
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

On 31 Dec 2005 06:37:11 -0800, "Gavin Deane" <deane_gavin@hotmail.com>
wrote in comp.lang.c++:
[color=blue]
>
> Manuel wrote:
>[color=green]
> > W Marsh wrote:
> >[color=darkred]
> > > Portability. The GL Red Book says:
> > >
> > > "Implementations of OpenGL have leeway in selecting which C data type to
> > > use to represent OpenGL data types. If you resolutely use the OpenGL
> > > defined data types throughout your application, you will avoid
> > > mismatched types when porting your code between different implementations."[/color]
> >
> >
> > Thanks.
> > But this is a problem with C++ too?
> > If I declare an "int" under windows, maybe different from an "int" under
> > linux or OSX ?[/color]
>
> Yes. There is no requirement for an int to be the same size on every
> platform.
>
> sizeof returns a number of bytes. You are guaranteed that
>
> sizeof char == 1
> sizeof char <= sizeof short <= sizeof int <= sizeof long
> CHAR_BIT >= 8
>
> where CHAR_BIT, available by including the <climits> or <limits.h>
> header, is the number of bits in a char (i.e. in a byte).
>
> I believe there are also some *minimum* size guarantees for the
> integral types. I'm not sure what they are, or whether they are
> specified as a number of bits, a number of bytes, or a range of values
> that must be accomodated.[/color]

They are specified by a range of values, but if look at the binary
representation of the values you can easily work out the minimum
number of bits, although the actual bit usage may be greater because
padding bits are allowed in all but the "char" types.

You can see the ranges for all the integer types, including the C
"long long" type that is not part of C++, yet, here:

http://www.jk-technology.com/c/inttypes.html#limits

You can easily work out the required minimum number of bits from the
required ranges:

char types, at least 8 bits
short int, at least 16 bits
int, at least 16 bits
long, at least 32 bits
long long (C since 1999, not official in C++) 64 bits

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
  #8  
Old January 1st, 2006, 01:35 PM
Gavin Deane
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

Jack Klein wrote:[color=blue]
> You can see the ranges for all the integer types, including the C
> "long long" type that is not part of C++, yet, here:
>
> http://www.jk-technology.com/c/inttypes.html#limits
>
> You can easily work out the required minimum number of bits from the
> required ranges:
>
> char types, at least 8 bits
> short int, at least 16 bits
> int, at least 16 bits
> long, at least 32 bits
> long long (C since 1999, not official in C++) 64 bits[/color]

Thanks Jack. A useful reference.

Gavin Deane

  #9  
Old January 2nd, 2006, 12:05 PM
Manuel
Guest
 
Posts: n/a
Default Re: Difference between "float" and "GLfloat" ?

Ron Natalie wrote:
[color=blue][color=green]
>> But this is a problem with C++ too?
>> If I declare an "int" under windows, maybe different from an "int"
>> under linux or OSX ?[/color]
>
>
> Yes. This is why there are typedefs in the various API's that use C
> and C++ to nail this down on a particular implementation. Even in
> the standard language we have things like size_t.[/color]

Thanks.
But I've some difficult yo understand the problem.

Maybe a loop go "out of size"?
The problem is not limited to openGL, but it is about all multiplatform
application?
If yes...how solve the problem without using GLtypes?

Can you show an example where using various "int types" can crash or
ruin the application?

Thanks!

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles