OpenGL函数中的'f'代表什么意思(例如glRotatef)?

3

几乎所有OpenGL(或至少是PyOpenGL)函数都以“f”结尾,例如glRotatef和glColor3f等,但我无法找到它的含义。它是否像1.0f一样,默认使用单精度浮点数?

顺带一提(如果我可以问两个问题的话),glColor3f和glColor3fv之间有什么区别?


你看过 glColor 吗? - vallentin
我不知道它可以没有后缀,所以我没有从那个角度去查看。谢谢你的指点!结果证明我的猜测是正确的哈哈。 - polarisfox64
1个回答

4
f表示该函数期望传入一个float类型的参数。如果有一个i,那么该函数就会期望传入一个int类型的参数。v代表向量,因此glColor3fv函数期望传入一个"浮点向量",也就是一个由浮点数组成的数组。
这在glColor文档中得到了清楚的反映。
void glColor3f(GLfloat red, GLfloat green, GLfloat blue);
void glColor3fv(const GLfloat *v);

该格式在规范中有更详细的解释:

A final v character, if present, indicates that the command takes a pointer to an array (a vector) of values rather than a series of individual arguments.

In general, a command declaration has the form

rtype Name{∈1234}{∈ b s i i64 f d ub us ui ui64}{∈v}

rtype is the return type of the function. The braces ({}) enclose a series of type descriptors (see the table bellow), of which one is selected. ∈ indicates no type descriptor.

If there are no letters, then the arguments’ type is given explicitly. If the final character is not v, then N is given by the digit 1, 2, 3, or 4 (if there is no digit, then the number of arguments is fixed).

If the final character is v, then only arg1 is present and it is an array of N values of the indicated type.

+------+----------------------------------+
| Type | Descriptor Corresponding GL Type |
+------+----------------------------------+
| b    | byte                             |
| s    | short                            |
| i    | int                              |
| i64  | int64                            |
| f    | float                            |
| d    | double                           |
| ub   | ubyte                            |
| us   | ushort                           |
| ui   | uint                             |
| ui64 | uint64                           |
+------+----------------------------------+

OpenGL 4.5 Specification, Page 11 and 12

符号 ∈ 表示 "是集合中的元素"。

同样的原则也适用于其他事物,比如 GL_RGBA32FGL_RGBA8I。这不仅限于OpenGL,各种库都使用其期望或返回类型的前缀。


谢谢!正是我所需要的,那个链接页面非常有用。 - polarisfox64
1
如果你对于为什么所有这些都是必需的感到困惑,那是因为OpenGL是一个C API,而C语言没有函数重载。 - peppe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接