hi
how can i convert pixel to [-1..1]coordinate in opengl?
witch function?
i want to write a program that is work with glutmousefunc(),
when i click on the screen a ball is appear on it where clicked. but mouse work with pixel and circle work with coordinate between -1 and 1
You have to use float or double to do that right. like:
1 2
double v = 2.0 / (double)screen-width;
int x = round(v * (double)mouse-x - 1.0);
I know it's a bit messy with those back and forth casting, but if you divide integer values you quickly just get 0.
Also, I wrote that in two lines to make it less messy. I write this in one line in my own programs.
Also, also, the function round() doesn't really exist/work this way, but I think you know what I mean. I usually just cast back to int, I don't really care for a half-pixel error.