SDL, from (0,0) to (w, h) or (w-1, h-1)?

I have been studying OpenGL and SDL lately, and I am pretty confused about the coordinate system in SDL and glOrtho. I read several manuals about the SDL coordinate system, which says that 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, it means that there is one additional pixel.

In addition, using the OpenGL glOrtho function, I saw all the examples in which the coordinate system was changed to one similar to SDL, in the following form:

glOrtho (0, screenWidth, screenHeight, 0, 1, -1); 

However, doesn't it make sense to do this instead ?:

 glOrtho (0, screenWidth-1, screenHeight-1, 0, 1, -1); 

Hope you guys can clarify this to me, thanks.

+4
source share
1 answer

A view of the same confusion as the beginning of new millennia. I will try to explain:

Take some piece of paper with a grid and mark the intersection of the grid as your origin, i.e. coordinate 0,0. Measure the width, for example 9 mesh units in one direction, mark it. Now count the number of cells that you measured. Let me illustrate:

 0 1 2 3 4 5 6 7 8 9 <- grid lines; coordinate range | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |0|1|2|3|4|5|6|7|8| <- cell index/offset 

So, you have a grid 9 wide, but it has only 9-1 = 8 cells (for example, pixels). The ranges you give glOrtho are out of range.

+7
source

Source: https://habr.com/ru/post/1339544/


All Articles