## GL view bounds question/quirk

Nibbie
Posts: 2
Joined: 2009.07
Post: #1
I have a question regarding OpenGL and setting up view bounds for things like glOrtho2D for example.

I see some examples that are like:

glOrtho2D(-height/2, height/2, -width/2, width/2);

or even

glOrthof(-240.0f, 240.0f, -160.0f, 160.0f, -1.0f, 1.0f);

My question is, shouldn't one value for the height and one for the width be -1? like so, if you want pixel for pixel accuracy?

glOrtho2D(-height/2, height/2-1, -width/2, width/2-1);

glOrthof(-240.0f, 239.0f, -160.0f, 159.0f, -1.0f, 1.0f);

This kinda confuses me. Because one thing that is for sure is, if a screen has 1280 x 800 pixels, that 0 to 1279 and 0 to 799.

Please let me know if I am missing something, I would like to proceed with some logic.

Laters...
Member
Posts: 30
Joined: 2009.02
Post: #2
It's due to it being a coordinate system, not an array of pixels.

It's exactly like a sheet of graph paper, with each x,y coordinate corresponding to an intersection between two lines. The pixels themselves are the squares those lines form. So those coordinates aren't to the pixels themselves, but the corners of each pixel. A line of 10 pixels, if counted, will indeed span 0-9, but if you map out the coordinates, you'll see the left two corners of the first pixel will be (0, 0) and (0, 1), while the right side of the last pixel will be (10, 0), (10, 1).
Sage
Posts: 1,234
Joined: 2002.10
Post: #3
Think about the simple case of a window that is only 1 pixel wide. You'd set an ortho transform to cover 0 to 1, not 0 to 0.
Nibbie
Posts: 2
Joined: 2009.07
Post: #4
got it!

That makes sense.