#include "main.h" #include #include struct obj { unsigned int vertex, vao, vbo; }; mesh_t create_mesh( float * mesh ) { struct obj * p; p=malloc(sizeof(struct obj)); p->vertex=(*mesh)/3; glGenVertexArrays( 1, &p->vao ); glGenBuffers( 1, &p->vbo ); glBindVertexArray( p->vao ); glBindBuffer( GL_ARRAY_BUFFER, p->vbo ); glBufferData( GL_ARRAY_BUFFER, (p->vertex*3)*sizeof(float), mesh+1, GL_STATIC_DRAW ); glVertexAttribPointer( 0,3,GL_FLOAT, 0, 3*sizeof(float), NULL ); glEnableVertexAttribArray(0); return p; } void destroy_mesh( mesh_t p ) { struct obj * obj ; obj = p; glDeleteVertexArrays( 1, &obj->vao ); glDeleteBuffers( 1, &obj->vbo ); free( p ); } void draw_mesh( mesh_t p ) { struct obj * obj=p; glBindVertexArray( obj->vao ); #ifdef DEBUG { int i; for( i=0; ivertex;i+=3 ) glDrawArrays(GL_LINE_LOOP, i, 3 ); } #else glDrawArrays(GL_TRIANGLES, 0, obj->vertex ); #endif }