How to map 256 numbers between -1 and 1

Hi everyone,

I am learning Open GL programming. I am using the glVertex3f() function which specifies the coordinates for x, y, and z axis. However, the coordinates accept values between -1 and 1. If I have an image that is 256x256...I want to be able to point to... lets say the coordinate (35, 75).

I'm trying to think of a formula that will convert/map 256 values in between -1 and 1. For example...

Value 0 ==> -1
.
.
Value 64 ==> xxx // How can we determine this value?
.
.
Value 128 ==> xxx // How can we determine this value?
.
.
Value 256 ==> 1

This is probably very simple... but I can't seem to figure out the formula.
Thanks in advance.
You have some misconceptions there.
Firstly, glVertex3f has no limit to input range (except the limit of float itself). It's a bit hard to explain how things work without getting too deep, but by using functions glOrtho (2d) or glFrustum (3d) you can change coordinate systems.
Secondly, texture is not a bunch of points drawn with glBegin(GL_POINTS). To draw a texture you first load it into gl and then draw a textured square (see some tutorial about it)
Lastly, mapping values from one range to another is indeed simple. Let's say we have y between y_min and y_max and want to convert it to x between x_min and x_max. x = (y-y_min)/(y_max-y_min)*(x_max-x_min)+x_min. It may seem complex but in your case it's just x = y/256*2-1;. Note that y has to be float. If y is int then so is y/256*2-1 which would mean -1, 0 or 1.
ah - very simple indeed, thank you hamsterman!
Topic archived. No new replies allowed.