I have been learning OpenGL and SDL lately and I’ve become rather confused about the coordinate system in SDL and glOrtho. I’ve read a few tutorials about the SDL’s coordinate system that says the coordinates go from (0,0) to (w, h) which does not make sense to me. If if the width goes from 0 to w then that means there is one extra pixel.
Also, with the OpenGL glOrtho function, I’ve seen all examples where the coordinate system is changed to one that’s similar to SDL take the following form:
glOrtho (0, screenWidth, screenHeight, 0, 1, -1);
However doesn’t it make more sense to make it this instead?:
glOrtho (0, screenWidth-1, screenHeight-1, 0, 1, -1);
Hope you guys can clarify this for me, thanks.
Kind of the same confusion like the beginning of the new millenia. I’ll try to explain:
Take some piece of grid-ruled paper and mark some grid crossing as your origin, i.e. 0,0 coordinate. Measure a width of, say 9 grid units in one direction, mark it. Now count the number of cells you measured. Let me illustrate:
So you’ve got a grid of width 9, but there are only 9-1=8 cells (e.g. pixels) within. The ranges you give to glOrtho are the limits of the range.