PDA

View Full Version : Using variables...



Slashdot'd
05-09-2004, 11:24 AM
In functions like glColor4f(), how can I use variables? (because you have to use a number between 0 and 1.0 with f stuck to the end of it.

Bob
05-09-2004, 12:03 PM
Just pass the variable containing the value to glColor4f.

GLfloat foo = 0.2;
glColor4f(foo, 0.3, 0.4, 1);

KeSh
05-09-2004, 12:04 PM
Do we really need the 'f' stuck at the end?

Slashdot'd
05-09-2004, 12:12 PM
Apperantly we don't.
Well, that speeds up production time, ohh, %1000.

ce110ut
05-09-2004, 04:19 PM
actually, on some compilers [visual studio c++ 6.0] you have to append the 'f' otherwise the compiler complains. gcc suite doesn't.

it might be annoying, [and not to be a troll] but what slashdot'd said is true - compilers will make a float out of a number with an 'f' appended, versus them automatically[?] making floating-point numbers double...

just a thought...

:regards:

Andrew Davey
05-09-2004, 10:22 PM
there are other number formates for example
glColor3ub(255,255,255);
glColor3d(1,1,1);

Where ub is unsigned bit(or byte, i think) and is from 0-255 and d is int but not sure of its range.

So no you dont always need the f, but it would be better for the program if you could tell it that as it wouldnt have to guess, eventually something bad might happen.

At least that what i think and understand.

dorbie
05-09-2004, 10:50 PM
The appended f tells the compiler that the number you intend to create in memory is a single precision float. This is ANSI C and nothing to do with OpenGL. Also of course you can use a variable as the float argument.

You need to get a book on basic C programming, these questions are not OpenGL questions.