0.1 Graph cube

This commit is contained in:
PedroEdiaz
2024-09-04 22:35:31 +00:00
commit cce685d90c
12 changed files with 675 additions and 0 deletions

50
src/mesh.c Executable file
View File

@@ -0,0 +1,50 @@
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <stdlib.h>
struct obj
{
unsigned int vertex, vao, vbo;
};
void * create_mesh( int * mesh )
{
struct obj * p;
p=malloc(sizeof(struct obj));
p->vertex=(*mesh)/4;
glGenVertexArrays( 1, &p->vao );
glGenBuffers( 1, &p->vbo );
glBindVertexArray( p->vao );
glBindBuffer( GL_ARRAY_BUFFER, p->vbo );
glBufferData( GL_ARRAY_BUFFER, (p->vertex*4)*sizeof(int), mesh+1,
GL_STATIC_DRAW );
glVertexAttribPointer( 0,3,GL_INT, 0, 4*sizeof(int), NULL );
glEnableVertexAttribArray(0);
glVertexAttribPointer( 1,1,GL_INT, 0, 4*sizeof(int),
(void*)(3*sizeof(int)) );
glEnableVertexAttribArray(1);
return p;
}
void destroy_mesh( void * p )
{
struct obj * obj ;
obj = p;
glDeleteVertexArrays( 1, &obj->vao );
glDeleteBuffers( 1, &obj->vbo );
free( p );
}
void draw_mesh( void * p )
{
struct obj * obj=p;
glBindVertexArray( obj->vao );
glDrawArrays(GL_TRIANGLES, 0, obj->vertex );
}