arrays - glVertex3fv 和 glVertex3f 之间的区别

标签 arrays pointers opengl indexing opengl-3

static GLfloat vdata[12][3] = {
    {-X, 0.0, Z}, {X, 0.0, Z}, {-X, 0.0, -Z}, {X, 0.0, -Z},
    {0.0, Z, X}, {0.0, Z, -X}, {0.0, -Z, X}, {0.0, -Z, -X},
    {Z, X, 0.0}, {-Z, X, 0.0}, {Z, -X, 0.0}, {-Z, -X, 0.0}
};
static GLint tindices[20][3] = {
    {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
    {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
    {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
    {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11}
};

...

for (i = 0; i < 20; i++) {
    glBegin(GL_TRIANGLES);
    glColor3f(0.5, 0.0, 0.0);
    glVertex3fv(&vdata[tindices[i][0]][0]);
    glColor3f(0.0, 1.0, 1.0);
    glVertex3fv(&vdata[tindices[i][1]][0]);
    glColor3f(0.0, 0.6, 1.0);
    glVertex3fv(&vdata[tindices[i][2]][0]);
    glEnd();
}

在这段代码中,glvertex3fv 需要接受 3 个参数吗?在我看来,只需要一个论证,我错了吗?它们有什么区别(即 glvertex3f 和 glvertex3fv)?

最佳答案

你说得对!它只需要一个参数,即指针。在您的示例中,您通过在 vdata 中声明三个浮点变量中的第一个变量(通过使用 [0])的位置,将指针传递给 vertex3f(通过使用 &) 。 tindices[i][j] 指定您想要从 vdata 中获得哪个 vertex3f。 :) 使用 glVertex3f,您可以通过 glVertex3fv 传递 3 个浮点变量,该指针指向三个浮点变量(如 GLfloat)。

关于arrays - glVertex3fv 和 glVertex3f 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20928285/

相关文章:

c - 需要帮助理解我的示例的 malloc(0)

c++ - glGetTexImage() 在 ATI 卡上不能正常工作?当 mip 级别 > 0 时失败

arrays - powershell 数组的方法(Clear、ForEach、Where 等)在哪里定义?

arrays - 将数组与引用数组中的值匹配 - Perl

c++ - 通过指针更改数组中元素的值 - vector<int> C++

c - C 中与 ‘operator*’ (操作数类型为 ‘node’ )不匹配

c - 为什么 GLfloat 需要全局作用域?

c++ - 在特定显示器上为 GL 打开 X11 窗口

arrays - 复制go slices键值

arrays - 初学者 : When working with arrays, 为什么这个有效但这个不行?