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...
Quote this message in a reply
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).
Quote this message in a reply
Sage
Posts: 1,232
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.
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2009.07
Post: #4
got it!

That makes sense.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  When to create custom OpenGL view instead of subclass NSOpenGL view Coyote 37 22,673 Oct 20, 2009 08:16 PM
Last Post: Coyote
  opengl view question Leroy 3 3,335 Jul 23, 2007 11:08 PM
Last Post: AnotherJake
  Perspective View Question, (GL_PROJECTION Matrix), and GUI hangt5 3 5,163 Sep 11, 2005 11:17 PM
Last Post: hangt5
  Strange Texturing Quirk Nick 0 2,069 Jun 5, 2005 09:42 PM
Last Post: Nick