Hi there,
I’m a newbie to Opengl and was wondering if i had a color value say 233, how do i convert that color value to opengl float color value? glColor3f(1.0, 0.0, 0.0) is how a color is set in opengl, but how do i covert say 233 to the 1.0 ro 0.0 equivalent?
think of it this way: you know that you want 0 (out of 255) to map to 0 (out of 1), and you want to map 255 (out of 255) to 1 (out of 1). Its reasonable to assume that this is a linear mapping, right? 'course it is. So, what is the equation of a line?
y=mx+c
where you need to find m (the gradient) and c (the y-intercept). two unknowns, but with two equations, ie.
1=255m+c … [2] and
0=0m+c … [1]
from [1] we can see that c is 0. substitution c into equation [1], we see that m is 1/255.0. so, to answer your question, you need the formula
b/255.0 = f
where b is your byte value and f is the corresponding f value