Thank you, Narishma.
And correction: you'll need a [number_of_triangles*3*3] array of GLfloats. Three GLfloats (x,y,z) for each vertex, and three vertices for each triangle. Rookie mistake. Sorry about that.
Code: Select all
void draw_object(char *name, SHADER_T *shader)
{
char *memory = NULL;
size_t bytes = ObjLoadFile("enemy.obj", &memory); //Load the file into the memory specified.
ObjModel *model = ObjLoadModel(memory, bytes);
GLfloat *vertices = (GLfloat *)malloc(model->nTriangle * 3 * sizeof(GLfloat));
int index = 0;
while(index != model->nTriangle*3)
{
vertices[index] = (GLfloat)model->TriangleArray[index].Vertex[0]; index++;
vertices[index] = (GLfloat)model->TriangleArray[index].Vertex[1]; index++;
vertices[index] = (GLfloat)model->TriangleArray[index].Vertex[2]; index++;
}
shader_select(shader);
GLsizei count = model->nTriangle * 3;
glVertexAttribPointer(0, count, GL_FLOAT, GL_FALSE, 0, vertices);
glDrawArrays( GL_TRIANGLES, 0, count );
obj_free_resources(model); //Free the objects resources.
}Even better, if possible, is to hold the data as a vbo on the gpu side, and just draw it every frame.panik wrote: You'll want to consider reading the .obj from file from disk only once, and send the resulting array(s) to a draw-function to draw the model every frame. It looks like you're loading it in and throwing it away every frame now.
That sounds great. I will move "look into vbo's" higher up in my priority list. Thanks!hexelpdkk wrote:Even better, if possible, is to hold the data as a vbo on the gpu side, and just draw it every frame.