OpenGL glGenVertexArrays错误

3
我正在尝试使用一个数组来创建5个顶点数组对象(VAO)并用于init()函数。
然而,glGenVertexArrays(5, &vao) 报错了,我不知道为什么会这样。
我猜我没有完全理解该函数的行为。
有人可以告诉我这是怎么回事吗?
以下是我的原始代码:
void
init(){
  // Subdivide a tetrahedron into a sphere
  Index = 0; tetrahedron( 1, 0, NumTimesToSubdivide-4 );
  Index = 0; tetrahedron( 0, 1, NumTimesToSubdivide-3 );
  Index = 0; tetrahedron( 0, 2, NumTimesToSubdivide-2 );
  Index = 0; tetrahedron( 0, 3, NumTimesToSubdivide-1);
  Index = 0; tetrahedron( 0, 4, NumTimesToSubdivide );

  // Create a vertex array object
  **glGenVertexArrays( 5, &vao ); // Error occurs on this line**
  for ( int i=0; i<5; i++ )
  {

    glBindVertexArray( vao[i] ); 
    GLuint buffer;
    glGenBuffers( 1, &buffer );
    glBindBuffer( GL_ARRAY_BUFFER, buffer );
    glBufferData( GL_ARRAY_BUFFER, sizeof(points[i]) + sizeof(normals[i]),NULL, GL_STATIC_DRAW );
    glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points[i]), &(points[i]) );
    glBufferSubData( GL_ARRAY_BUFFER, sizeof(points[i]),sizeof(normals[i]), &(normals[i]) );
  }
  // Load shaders and use the resulting shader program
  GLuint program = InitShader( "vshader.glsl", "fshader.glsl" );
  glUseProgram( program );

  // set up vertex arrays
  GLuint vPosition = glGetAttribLocation( program, "vPosition" );
  glEnableVertexAttribArray( vPosition );
  glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );

  GLuint vNormal = glGetAttribLocation( program, "vNormal" );
  glEnableVertexAttribArray( vNormal );
  glVertexAttribPointer( vNormal, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) );

  AmbientProduct = glGetUniformLocation(program, "AmbientProduct");
  DiffuseProduct = glGetUniformLocation(program, "DiffuseProduct");
  SpecularProduct = glGetUniformLocation(program, "SpecularProduct");
  LightPosition = glGetUniformLocation(program, "LightPosition");
  Shininess = glGetUniformLocation(program, "Shininess");
  Transformation = glGetUniformLocation( program, "Transformation" );
  View = glGetUniformLocation( program, "View" );
  Projection = glGetUniformLocation( program, "Projection" );

  glEnable( GL_DEPTH_TEST );
  glClearColor(0.0, 0.0, 0.0, 0.0 ); /* Black background */
}

以下是错误信息:

error C2664: 'void (GLsizei,GLuint *)' : cannot convert parameter 2 from 'GLuint (*)[5]' to 'GLuint *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

error C2664: 'void (GLsizei,GLuint *)' : cannot convert parameter 1 from 'GLuint (*)[5]' to 'GLsizei'
1>          There is no context in which this conversion is possible
1个回答

3

数组已经是指针了。您不需要使用&

glGenVertexArrays( 5, vao );

1
@PeterHwang:与其感谢他,不如通过点击旁边的勾选标记接受他的答案。 - Nicol Bolas

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