SDL坐标系,从(0,0)到(w,h)还是(w-1,h-1)?

时间:2011-02-13 12:59:01

标签: opengl graphics sdl

我最近一直在学习OpenGL和SDL,而且我对SDL和glOrtho中的坐标系感到困惑。我已经阅读了一些关于SDL坐标系的教程,其中坐标从(0,0)到(w,h),这对我来说没有意义。如果宽度从0变为w,那么这意味着有一个额外的像素。

此外,使用OpenGL glOrtho函数,我已经看到所有将坐标系更改为类似于SDL的示例的示例采用以下形式:

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

然而,将它改为更有意义吗?:

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

希望你们能为我澄清这一点,谢谢。

1 个答案:

答案 0 :(得分:7)

像新千年的开始一样混乱。我会试着解释一下:

取一些网格划线纸并标记一些网格交叉作为原点,即0,0坐标。测量一个方向上的9个网格单位的宽度,标记它。现在计算您测量的细胞数量。让我来说明一下:

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

所以你有一个宽度为9的网格,但其中只有9-1 = 8个单元格(例如像素)。你给glOrtho的范围是范围的限制。

相关问题