gpt4 book ai didi

opengl - SDL 坐标系,从 (0,0) 到 (w,h) 或 (w-1, h-1)?

转载 作者:行者123 更新时间:2023-12-02 12:50:00 25 4
gpt4 key购买 nike

我最近一直在学习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);

希望大家能帮我解释一下,谢谢。

最佳答案

有点像新千年的开始一样的困惑。我将尝试解释:

拿一张网格纸并标记一些网格交叉点作为原点,即 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 的范围是范围的限制。

关于opengl - SDL 坐标系,从 (0,0) 到 (w,h) 或 (w-1, h-1)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com