Hey,
I was wondering how i can set up orthographic projection so that 1 unit is equal to 64 pixels?
Thanks.
Hey,
I was wondering how i can set up orthographic projection so that 1 unit is equal to 64 pixels?
Thanks.
glOrtho(0, width/64, height/64, 0, -1, 1);
?
Okay,
So my window would be set to whatever(divisible by 64) and then 0,0 and 1,1 would be a square 64X64 pixels?
It doesn’t have to be divisible by 64 if you use floating point precision, e.g. divide by 64.0 (a double value) instead of 64 (an int value).
glOrtho takes 6 parameters: left, right, bottom, top, near and far. The values of these decide how vertex coordinates are mapped to the screen. left would be the vertex coordinate that is mapped to the left edge of the screen, in my example 0. Right is the same thing for the right edge, in my case width/64.0. The x-coordinate of a vertex is therefore inside the screen if it is between 0 and width/64.0.
For a real example, let’s say your window is 640x480. With the glOrtho call I posted before, it would turn out to glOrtho(0, 10, 7.5, 0, -1, 1). A line drawn from (0, 0) to (1, 1) would therefore be mapped to (0, 0) and (64, 64) in pixels.
Try to experiment with it a little. It’s not that hard to get right. =D