void init_cube(void){
makeCube(cbr_points,cbr_normals);
glGenVertexArrays(1,&VAID_cube);
glBindVertexArray(VAID_cube);
glGenBuffers(1,&VBID_cube);
glBindBuffer(GL_ARRAY_BUFFER,VBID_cube);
glBufferData(GL_ARRAY_BUFFER,sizeof(vec4)*cbr_points.size()+sizeof(vec3)*cbr_normals.size(),0,GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,0,cbr_points.size()*sizeof(vec4),cbr_points.data());
glBufferSubData(GL_ARRAY_BUFFER,cbr_points.size()*sizeof(vec4),cbr_normals.size()*sizeof(vec3),cbr_normals.data());
GLuint vPosition = glGetAttribLocation(g_IDShader,"vPosition");
glEnableVertexAttribArray(vPosition);
glVertexAttribPointer(vPosition,4,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(0));
GLuint vNormal = glGetAttribLocation(g_IDShader,"vNormal");
glEnableVertexAttribArray(vNormal);
glVertexAttribPointer(vNormal,3,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(cbr_points.size()*sizeof(vec4)));
}
void setVAVBObject( void )
{
// Set VAO
glGenVertexArrays ( 1, &g_VAID );
glBindVertexArray ( g_VAID );
// Set vertex position, normal and elements - VBO
glGenBuffers ( 1, &g_VBIDvertices );
glBindBuffer ( GL_ARRAY_BUFFER, g_VBIDvertices );
glBufferData ( GL_ARRAY_BUFFER, g_bunny.vertices.size() * sizeof(g_bunny.vertices[0]), g_bunny.vertices.data(), GL_STATIC_DRAW );
glGenBuffers ( 1, &g_VBIDnormals );
glBindBuffer ( GL_ARRAY_BUFFER, g_VBIDnormals );
glBufferData ( GL_ARRAY_BUFFER, g_bunny.normals.size() * sizeof(g_bunny.normals[0]), g_bunny.normals.data(), GL_STATIC_DRAW );
// Ex-TODO: Computing normal
// Set up the indices buffer - flat shading does not use indices
glGenBuffers ( 1, &g_IBIDelements );
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, g_IBIDelements );
glBufferData ( GL_ELEMENT_ARRAY_BUFFER,
g_bunny.elements.size() * sizeof(g_bunny.elements[0]),
g_bunny.elements.data(), GL_STATIC_DRAW );
GLuint vPosition = glGetAttribLocation( g_IDShader, "vPosition" );
glEnableVertexAttribArray( vPosition );
glBindBuffer( GL_ARRAY_BUFFER, g_VBIDvertices);
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );
GLuint vNormal = glGetAttribLocation( g_IDShader, "vNormal" );
glEnableVertexAttribArray( vNormal );
glBindBuffer( GL_ARRAY_BUFFER, g_VBIDnormals);
glVertexAttribPointer( vNormal, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );
}
void displayBunny( void ) {
int size;
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, g_IBIDelements );
glGetBufferParameteriv ( GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size );
glDrawElements ( GL_TRIANGLES, size/sizeof(GLushort), GL_UNSIGNED_SHORT, 0 );
}
void displayCube( void ) {
glBindVertexArray(VAID_cube);
glBindBuffer(GL_ARRAY_BUFFER,VBID_cube);
glDrawArrays(GL_TRIANGLES,0,cbr_points.size());
}
私はobjファイルと頂点配列を使用しているので、別の方法で1つのシーンに表示したいです。
この関数を離散的に使用すると、うまく表示されますが、好きなように使用すると
displayBunny();
displayCube();
エラーが発生します。プリミティブを表示する方法を 1 つだけ選択する必要がありますか?