std::vector<IndexedVAO> load_model(const char * filename) { std::vector<IndexedVAO> vec; std::vector<unsigned> indices; Assimp::Importer imp; const aiScene * scene = imp.ReadFile(filename, aiProcess_Triangulate | aiProcess_PreTransformVertices | aiProcess_GenNormals ); if(scene == NULL) printf("failed to open %s\n", filename); else { vec.reserve(scene->mNumMeshes); // For each mesh for(unsigned i=0; i<scene->mNumMeshes; ++i) { aiMesh & mesh = *scene->mMeshes[i]; indices.reserve(mesh.mNumFaces*3); // For each face for(unsigned f=0; f<mesh.mNumFaces; ++f) { aiFace & face = mesh.mFaces[f]; assert(face.mNumIndices == 3); indices.push_back(face.mIndices[0]); indices.push_back(face.mIndices[1]); indices.push_back(face.mIndices[2]); } IndexedVAO vao = make_indexed_vao(indices.data(), indices.size()); glBindVertexArray(vao.handle); vao.mode = GL_TRIANGLES; // Positions glBindBuffer(GL_ARRAY_BUFFER, make_vbo(mesh.mVertices, mesh.mNumVertices*sizeof(aiVector3D)) ); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); // Normals glBindBuffer(GL_ARRAY_BUFFER, make_vbo(mesh.mNormals, mesh.mNumVertices*sizeof(aiVector3D)) ); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(1); vec.push_back(vao); } } // else return vec; }
void draw_obj_instances(struct model *model, float *t, int count) { struct mesh *mesh; int i; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); for (mesh = model->mesh; mesh; mesh = mesh->next) { if (!mesh->vbo) make_vbo(model, mesh); glBindTexture(GL_TEXTURE_2D, mesh->material->texture); glBindBuffer(GL_ARRAY_BUFFER, mesh->vbo); glVertexPointer(3, GL_FLOAT, 8*4, (float*)0+0); glTexCoordPointer(2, GL_FLOAT,8*4, (float*)0+3); glNormalPointer(GL_FLOAT, 8*4, (float*)0+5); for (i = 0; i < count; i++) { glPushMatrix(); glTranslatef(t[i*3+0], t[i*3+1], t[i*3+2]); glDrawArrays(GL_TRIANGLES, 0, mesh->len * 3); glPopMatrix(); } } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); }
IndexedVAO make_indexed_vao(unsigned * indices, size_t count) { IndexedVAO vao; glGenVertexArrays(1, &vao.handle); vao.count = count; vao.index_buffer = make_vbo(indices, count*sizeof(unsigned), GL_ELEMENT_ARRAY_BUFFER); return vao; }
VAO make_grid(unsigned span) { if(!(span%2)) ++span; VAO vao = make_vao(); unsigned vertex_count = 3*2*2*span; float start_coord = -(span-1.0f) / 2.0f; float vertices[vertex_count]; int line_index = 0; for(unsigned i=0; i<vertex_count; ) { vertices[i++] = start_coord + line_index; vertices[i++] = 0.0f; vertices[i++] = start_coord; vertices[i++] = start_coord + line_index; vertices[i++] = 0.0f; vertices[i++] = -start_coord; vertices[i++] = start_coord; vertices[i++] = 0.0f; vertices[i++] = start_coord + line_index; vertices[i++] = -start_coord; vertices[i++] = 0.0f; vertices[i++] = start_coord + line_index; ++line_index; } unsigned vbo = make_vbo(vertices, sizeof(vertices)); glBindBuffer(GL_ARRAY_BUFFER, vbo); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); vao.count = sizeof(vertices) / sizeof(float) / 3; vao.mode = GL_LINES; return vao; }
void dt_circle_note_on::change_rshape(int type){ seq->setRhythmShape(type); make_vbo(); }