Document code, and clean up
This commit is contained in:
37
src/mesh.c
37
src/mesh.c
@@ -7,8 +7,15 @@ struct obj
|
||||
unsigned int vertex, vao, n_vbo, d_vbo;
|
||||
};
|
||||
|
||||
/*
|
||||
In this function we load all the vertex and normal datas on two
|
||||
diferents buffers, so we can access the coordanates that we want
|
||||
to display using the layout location in GLSL.
|
||||
This trick can be done with glVertexAttribPointer.
|
||||
*/
|
||||
mesh_t create_mesh( float * d, float * n, unsigned char * coordanate )
|
||||
{
|
||||
unsigned char i;
|
||||
struct obj * p;
|
||||
|
||||
p=malloc(sizeof(struct obj));
|
||||
@@ -22,27 +29,25 @@ mesh_t create_mesh( float * d, float * n, unsigned char * coordanate )
|
||||
glBindBuffer( GL_ARRAY_BUFFER, p->d_vbo );
|
||||
glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), d+1,
|
||||
GL_STATIC_DRAW );
|
||||
glVertexAttribPointer( 0,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[0]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer( 1,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[1]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer( 2,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[2]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer( 3,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[3]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(3);
|
||||
|
||||
for( i=0; i<4; ++i )
|
||||
{
|
||||
glVertexAttribPointer( i,1,GL_FLOAT, 0, 3*sizeof(float),
|
||||
(float*)(coordanate[i]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(i);
|
||||
}
|
||||
|
||||
glGenBuffers( 1, &p->n_vbo );
|
||||
glBindBuffer( GL_ARRAY_BUFFER, p->n_vbo );
|
||||
glBufferData( GL_ARRAY_BUFFER, p->vertex*3*sizeof(float), n+1,
|
||||
GL_STATIC_DRAW );
|
||||
glVertexAttribPointer( 4,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[0]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(4);
|
||||
glVertexAttribPointer( 5,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[1]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(5);
|
||||
glVertexAttribPointer( 6,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[2]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(6);
|
||||
glVertexAttribPointer( 7,1,GL_FLOAT, 0, 3*sizeof(float), (float*)(coordanate[3]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(7);
|
||||
|
||||
for( i=0; i<4; ++i )
|
||||
{
|
||||
glVertexAttribPointer( i+4,1,GL_FLOAT, 0, 3*sizeof(float),
|
||||
(float*)(coordanate[i]*sizeof(float)) );
|
||||
glEnableVertexAttribArray(i+4);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user