Archived

This topic is now archived and is closed to further replies.

Kaptain Kangaroo

A few newbie questions..

Recommended Posts

A) Why would I use 1.0f instead of 1.0? B) Why use GLfloat, GLuint instead of normal floats and     unsigned integers? C) I'm sure I'll be back with more questions when I think of     them Edited by - Kaptain Kangaroo on August 1, 2001 8:26:28 AM Edited by - Kaptain Kangaroo on August 1, 2001 8:27:41 AM

Share this post


Link to post
Share on other sites
sprochet    122
the f in 1.0f is just to make the compiler now that the value is a floating point number. If you don''t specify the f it will asume it''s a double and cast it to a float..

GLfloat, GLuint and so on are just typecasts defined in gl.h and are kind of cool. If the OpenGL ARB suddenly desides that a GLint should be 64 bits instead of 32 (the usual int) all you would have to do was to recompile your old code and it would work (that is if you used the opengl typedefs)

Share this post


Link to post
Share on other sites
Dragonus    122
Also on the 1.0f vs. 1.0 deal, OpenGL functions have several different flavours of parameters. Take the glVertex*() functions. Two different flavours of the function are glVertex3f() and glVertex3d(). The "3" stands for the number of parameters the function takes, but the last letter stands for the type of data the function expects. In the case of the "3f" function, it expects floating point values (GLfloat). In the "3d", double-precision values (GLdouble).

NeHe uses the floating-point routines because of speed, I presume, because double-precision values take twice as long to move in and out of registers; hence why we use floats and 1.0f.

~ Dragonus

Share this post


Link to post
Share on other sites
davepermen    1047
if you write 1.0 instead of 1.0f, you possibly will write 1 instead of 1.f or 1.0f, too, and in this case, its even an integer..

now if you have ( in c++ ) an overloaded function like float square_root( float x ) and int square_root( int x ), and write square_root( 2 ), you get the integerfunction => you get returned 1, or 2 ( i think 1.. ) instead of 1.414etc.. means if you dont use .f at the end, you possibly get integercalculations, like in

float x = 1/2; it can, just _can_ be sometimes interpreted as integer-calculation, and you get errors

if u use printf, a c-function, you even get the wrong value if you write printf("%f\n", 1 ), cause then the 1 is , as usually, interpreted as integer-one, and this is binary different written than the floating-point-one.. and you dont get 1 onto the screen

the GLuint, GLfloat is something like objectorientet, for "now i know its a value from opengl".. i use it for texture-id''s but for nothing else..

we wanna play, not watch the pictures

Share this post


Link to post
Share on other sites