View Full Version : integer value to GLfloat value

05-06-2004, 01:24 PM
I have a toolbar that is outputting a int, and i want this int to be in my GLfloat LightPosition[]. How can i get it from a=1 into my LightPostion where it must be a=1.0f.

Andrew Davey
05-06-2004, 01:53 PM
assuming you are using C you can do one of two things, the first am pretty sure is right, the second works in JAVA but not sure about C.

Typecast the variable

int intVariable = 1;
GLfloat i_want_this_one;

i_want_this_one = (GLfloat) intVariable;That should work, as for the second one, if you have the output variable to be a float and the function returns an int it should be fine, as an int can fit into a floats space.

GLfloat hello;

hello = method_that_returns_int();Pretty sure the second works, but not completely sure.

05-06-2004, 02:07 PM
In C such type conversions are done automatically.

int intVariable = 1;
GLfloat i_want_this_one;
i_want_this_one = intVariable;

Will give you the result you want too. But it is clearer for your if you keep the (GLfloat) for explicit type conversion.