几乎所有OpenGL(或至少是PyOpenGL)函数都以“f”结尾,例如glRotatef和glColor3f等,但我无法找到它的含义。它是否像1.0f一样,默认使用单精度浮点数?
顺带一提(如果我可以问两个问题的话),glColor3f和glColor3fv之间有什么区别?
几乎所有OpenGL(或至少是PyOpenGL)函数都以“f”结尾,例如glRotatef和glColor3f等,但我无法找到它的含义。它是否像1.0f一样,默认使用单精度浮点数?
顺带一提(如果我可以问两个问题的话),glColor3f和glColor3fv之间有什么区别?
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
, thenN
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 onlyarg1
is present and it is an array ofN
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 | +------+----------------------------------+
符号 ∈ 表示 "是集合中的元素"。
同样的原则也适用于其他事物,比如 GL_RGBA32F
与 GL_RGBA8I
。这不仅限于OpenGL,各种库都使用其期望或返回类型的前缀。