View Full Version : A question about glVertex
I have just started OpenGL.
I know the variable of glVertex3f should be float. But I don't know the meaning of "f" here. You know, there can't be any datafile in the form of "~.~f". How can I use the data like 123.4567 in glVertex3f?
Thanks for your help!
there are two type's of 'f', here. The first instance, after glVertex3, is to give the gl vertex func a unique identifier based on its parameter list; C doesn't know anything about overloading functions and can't do this automagically.
The second f after a numeric literal is to cast the number to a float. True, it LOOKS ike a float because it has a decimal point, but the compiler *may* treat 1.2 as a double rather than a float. Its a shorthand form of (float)1.2
In answer to your second question, there's nothing stopping you from leaving out the f, and the compiler should be happy about it, but it MIGHT warn you that you're casting a double to a float...
Thank you John.
Do you mean that I can use 123.456 directly in veterx3f(~,~,~)?
06-21-2001, 08:22 PM
yes, that is fine, i never include f's inside any () when i code.
yes, you can... but its not a blanket answer.
For example, suppose you were working in a 16bit compiler (to make the maths easier), and you wanted to divide some very big number by some other number, and you KNOW the result will fit in a 16 bit integer. You might do somthing like this:
so the answer is 0xFFFF, right? But some compilers get confused by 16bit integers and will *compile* the above code as:
which is not what you want, because the answer in this case is 1, not 0xFFFF.
So... the solution is to tell the compiler that some numbers are cool and special, like this:
by stickin' an L after the long number, you're telling the compiler to cast it to a long, and you'll magically get the answer you want.
er. but if you know your compiler is going to treat all blah.blah as floats and not doubles, then you can forget this. its, just, er, you know? for completeness.
06-22-2001, 12:09 PM
Dont mean to be picky, but I think you should always put f's in your real numbers, unless you explicitly want them treated as doubles.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.