glOrtho questions

sorry in advance for what may be a redundant question, since it’s pretty basic…

i would like to create a window that has exactly width pixels and height pixels, in their respective direction.

should i use glOrtho(0, width, 0, height, -1.0, 1.0) or glOrtho(0, width - 1, 0, height - 1, -1.0, 1.0)? i’ve seen it both ways.

also, i realize that pixels have an area, so when i think of a grid coordinate system over this window, am i going to have width and height full pixels or width - 1 and height - 1 pixels with an additional half pixel on each side (so the total either way is width x height pixels)?

pretty much the same question:
for the left, where is the exact point that gets clipped (less than the 0 pixel, exactly the 0 pixel, or less than or equal to the 0 pixel? In other words, if i draw a pixel at (0.0, y) should i see a full pixel, half a pixel, or no pixel at all.

i’ve also seen people suggest using glOrtho(-0.5, width - 0.5, -0.5, height - 0.5, -1.0, 1.0)
but i’m not sure what’s right.

can someone please clarify?

Thank you

Hi !

You cannot change the aspect of a pixel, this depends on your hardware (almost all video hardware today use aspect 1.0 for the pixels in most resolutions).

You can change the coordinate system so that a logical pixel is square though.

With gluPerspective you use the aspect parameter to do that.

With glOrtho you need to do something like:
left = 1.0;
right = 1.0;
top = -(height / width);
bottom = height / width);

Mikael

Hi again !

For your question about pixel alignment please read the faq on this website it has lots of information about this.

Mikael

The Ortho setting is something you specify, it’s unrelated to actual pixels unless YOU care for it.
If width and height are the window’s client area size, yes, the (0, width, 0, height) is correct.
Set the viewport to the same and you have a pixel per pixel match.
The pixels start on the left and bottom edge of the (0, 0) pixel and end on the left and bottom edge of the (width, height) pixel, which is the same as the right and upper edge of the (width - 1, height - 1) pixel. So you have exactly width * height pixels to draw to.

This is nice if you want to draw FILLED geometry exactly aligned to a pixel grid. You can use integer coordinates and e.g. quads will nicely fill pixels because you draw from one edge to the other edge of pixels with integer coordinates in that setup.

BUT, with points and lines, OpenGL rasterization follows the diamond exit rule and using integer coordinates here would draw exactly BETWEEN two pixels and depending on smallest floating point rounding errors lines can flip to either neighbour pixel.
To solve this, either draw points and lines adjusted to pixel centers by usind floats and adding (0.5, 0.5) to every coordinate or the other way round, adjust the glOrtho to start half a pixel to the lower left and use integer coordinates. There you are, the glOrtho(-0.5, …) explanation.

However if you want to draw pixel exact and mix filled primitives with points or lines you need to adjust glOrtho or coordinates for either the the filled or the unfilled primitives to be pixel precise.

Thank you Relic… this is exactly what i want to know.

i want to mix filled and unfilled primitives and draw both with floating point accuracy. So, it sounds like i should add/subtract 0.5 to one type.
assuming i am using glOrtho(0, width, 0, height) i think i want to add 0.5 to the line and point primitives… is that right?