voiddraw_bbox(structmesh*mesh){if(mesh->vertices.size()==0)return;// Cube 1x1x1, centered on originGLfloatvertices[]={-0.5,-0.5,-0.5,1.0,0.5,-0.5,-0.5,1.0,0.5,0.5,-0.5,1.0,-0.5,0.5,-0.5,1.0,-0.5,-0.5,0.5,1.0,0.5,-0.5,0.5,1.0,0.5,0.5,0.5,1.0,-0.5,0.5,0.5,1.0,};GLuintvbo_vertices;glGenBuffers(1,&vbo_vertices);glBindBuffer(GL_ARRAY_BUFFER,vbo_vertices);glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);glBindBuffer(GL_ARRAY_BUFFER,0);GLushortelements[]={0,1,2,3,4,5,6,7,0,4,1,5,2,6,3,7};GLuintibo_elements;glGenBuffers(1,&ibo_elements);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ibo_elements);glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(elements),elements,GL_STATIC_DRAW);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);GLfloatmin_x,max_x,min_y,max_y,min_z,max_z;min_x=max_x=mesh->vertices[0].x;min_y=max_y=mesh->vertices[0].y;min_z=max_z=mesh->vertices[0].z;for(inti=0;i<mesh->vertices.size();i++){if(mesh->vertices[i].x<min_x)min_x=mesh->vertices[i].x;if(mesh->vertices[i].x>max_x)max_x=mesh->vertices[i].x;if(mesh->vertices[i].y<min_y)min_y=mesh->vertices[i].y;if(mesh->vertices[i].y>max_y)max_y=mesh->vertices[i].y;if(mesh->vertices[i].z<min_z)min_z=mesh->vertices[i].z;if(mesh->vertices[i].z>max_z)max_z=mesh->vertices[i].z;}glm::vec3size=glm::vec3(max_x-min_x,max_y-min_y,max_z-min_z);glm::vec3center=glm::vec3((min_x+max_x)/2,(min_y+max_y)/2,(min_z+max_z)/2);glm::mat4transform=glm::translate(glm::mat4(1),center)*glm::scale(glm::mat4(1),size);/* Apply object's transformation matrix */glm::mat4m=mesh->object2world*transform;glUniformMatrix4fv(uniform_m,1,GL_FALSE,glm::value_ptr(m));glBindBuffer(GL_ARRAY_BUFFER,vbo_vertices);glEnableVertexAttribArray(attribute_v_coord);glVertexAttribPointer(attribute_v_coord,// attribute4,// number of elements per vertex, here (x,y,z,w)GL_FLOAT,// the type of each elementGL_FALSE,// take our values as-is0,// no extra data between each position0// offset of first element);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,ibo_elements);glDrawElements(GL_LINE_LOOP,4,GL_UNSIGNED_SHORT,0);glDrawElements(GL_LINE_LOOP,4,GL_UNSIGNED_SHORT,(GLvoid*)(4*sizeof(GLushort)));glDrawElements(GL_LINES,8,GL_UNSIGNED_SHORT,(GLvoid*)(8*sizeof(GLushort)));glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);glDisableVertexAttribArray(attribute_v_coord);glBindBuffer(GL_ARRAY_BUFFER,0);glDeleteBuffers(1,&vbo_vertices);glDeleteBuffers(1,&ibo_elements);}