Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Difference between GLfloat and float?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2002
    Posts
    4

    Difference between GLfloat and float?

    What's the difference between GLfloat and float?

    I also have problem understanding the following line of code:

    GLubyte yellow[] = {255, 255, 0, 255};

    What is this line of code for, and why is yellow an array?

  2. #2
    Member Contributor
    Join Date
    Feb 2002
    Location
    Italia
    Posts
    63

    Re: Difference between GLfloat and float?

    typedef float GLfloat;
    typedef something GLsomething;



    yellow = rgb(255,255,0)

    the ending 255 means "full color non translucent"

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2002
    Location
    istanbul,Turkey
    Posts
    19

    Re: Difference between GLfloat and float?

    it is 32-bit color.
    it is array because one byte is 8 bit you need 4 bytes to store it

    red green blue alpha
    255 , 255 , 0 , 255

    GLfloat is for cross-platform (to prevent conflicts with platforms)
    in windows,unix ... they are totally same

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Difference between GLfloat and float?

    Because of diffrences between some systems in which a float could be 16, 32 or 64 bit.
    So when gl.h defines GLfloat, it defines it a set size that does not change per system. This helps keeps openGL crossplatform compilant.

    openGL uses RGB values to define a color.
    (Red, Green, Blue), also your can add a transparency value to a color also, which is the fourth value.

    GLubyte yellow[] = {255, 255, 0, 255}; // Define the RGB values for the color yellow with no transparency.

    GLubyte white[] = {255, 255, 255, 255};

    GLubyte reb[] = {255, 0, 0, 255};

    The reason we do this is to cut down on code and having to remember numbers.

    Both of the folowing does the same thing, set's current color to draw with.

    glColor__( 255, 255, 0, 255);
    or
    glColor__( yellow );

    Just easy to remember yellow then a string of numbers, and less typing.



    Originally posted by sam02:
    What's the difference between GLfloat and float?

    I also have problem understanding the following line of code:

    GLubyte yellow[] = {255, 255, 0, 255};

    What is this line of code for, and why is yellow an array?

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2001
    Location
    Rennes
    Posts
    21

    Re: Difference between GLfloat and float?

    I would add that using GLfloat (or GLwhatever) can make easier the reading of your code,because of the prefix GL and the usage you make of the variable... GL variable for a GL usage...

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Difference between GLfloat and float?

    So when gl.h defines GLfloat, it defines it a set size that does not change per system.
    As with most, if not all features in OpenGL, the spec defines a lower limit, but not an upper. Same with the GL data types. Table 2.2 in the OpenGL 1.3 specification states the minimum length of GLfloat to 32 bit, but also says that an implementation may use more bits.

    So GL-datatypes can make portability easier, yes. But portable? Don't be so sure about that.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: Difference between GLfloat and float?

    You can avoid the size of byte changes from platform to platform by simply specifying it manually.

    float a:4;
    the :4 represents four bytes...

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Difference between GLfloat and float?

    Originally posted by mancha:
    You can avoid the size of byte changes from platform to platform by simply specifying it manually.

    float a:4;
    the :4 represents four bytes...
    Huh? What language are you working with?

    Test.cpp:
    Code :
    void main()
    {
    	float a:4;
    }
    Cygwin:
    $ g++ -o test test.cpp
    test.cpp: In function `int main(...)':
    test.cpp:3: parse error before `:'

    VC++:
    Compiling...
    test.cpp
    f:\cygwin\home\administrator\test.cpp(3) : error C2601: 'a' : local function definitions are illegal
    f:\cygwin\home\administrator\test.cpp(3) : error C2063: 'a' : not a function
    f:\cygwin\home\administrator\test.cpp(3) : error C2969: syntax error : ';' : expected member function definition to end with '}'
    Error executing cl.exe.

    test.exe - 3 error(s), 0 warning(s)
    Deiussum
    Software Engineer and OpenGL enthusiast

  9. #9
    Senior Member Regular Contributor
    Join Date
    Aug 2001
    Location
    England
    Posts
    173

    Re: Difference between GLfloat and float?

    That's legal syntax for bit fields, but AFAIK you can only use 'unsigned' or 'int' types (not float) with them, and the number specifies the number of BITS, not the number of BYTES.

    -Mezz

  10. #10
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Difference between GLfloat and float?

    Originally posted by Mezz:
    That's legal syntax for bit fields, but AFAIK you can only use 'unsigned' or 'int' types (not float) with them, and the number specifies the number of BITS, not the number of BYTES.

    -Mezz
    Ummm... yeah... changed float a:4; to unsigned int a:32;. Same errors. Not sure where you guys are reading this stuff, but I've never heard of that in any ANSI standard stuff I've ever seen. Maybe Delphi allows that, but for C/C++ most compilers usually have types like __int32, etc. That's not even an ANSI standard, though.
    Deiussum
    Software Engineer and OpenGL enthusiast

Page 1 of 2 12 LastLast

Similar Threads

  1. Why should i use GLfloat instead of float ?
    By greg2 in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 08-22-2007, 08:21 PM
  2. int, float VS. GLint, GLfloat
    By Evil-Dog in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 01-11-2002, 10:01 AM
  3. GLfloat and float.........
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-26-2001, 03:15 AM
  4. Different between GLfloat and float
    By Binqay in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 05-14-2001, 04:39 AM
  5. float vs. GLfloat
    By Glossifah in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-09-2001, 02:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean