That's our loading function done! Hold your horses, don't try and compile it yet we're not done! We still have to draw our model!
Code:
void Model::Draw(void) //declare our function
{
if(Loaded) //Check if it's loaded!
{ Now we can do the actual drawing!
Code:
glBegin(GL_TRIANGLES); //Say we're using triangles!
for(int i = 1; i < TriangleCount; i++) //For each face
{
glNormal3f(Verticies[Triangles[i].v1].Normal.x, Verticies[Triangles[i].v1].Normal.y, Verticies[Triangles[i].v1].Normal.z);
glVertex3f(Verticies[Triangles[i].v1].Pos.x, Verticies[Triangles[i].v1].Pos.y, Verticies[Triangles[i].v1].Pos.z);
glNormal3f(Verticies[Triangles[i].v2].Normal.x, Verticies[Triangles[i].v2].Normal.y, Verticies[Triangles[i].v2].Normal.z);
glVertex3f(Verticies[Triangles[i].v2].Pos.x, Verticies[Triangles[i].v2].Pos.y, Verticies[Triangles[i].v2].Pos.z);
glNormal3f(Verticies[Triangles[i].v3].Normal.x, Verticies[Triangles[i].v3].Normal.y, Verticies[Triangles[i].v3].Normal.z);
glVertex3f(Verticies[Triangles[i].v3].Pos.x, Verticies[Triangles[i].v3].Pos.
}
glEnd(); //Stop drawing! Now, that may look complicated but it really isn't! All of our vertices are stored in Vertices[50000] and they're in the order of what they were in the file. What the above is basically saying is "Draw the Vertex (Verticies[) of the current triangle's (Triangle[i]) point 1, 2 and 3 (.v1/2/3])"
Now we must close the function and if
Now you can compile it! Load in one of the provided models and the outcome should be whatever model you loaded! Cool huh!
If you used the starting code I provided you can toggle the grid on and off by pressing g and load a new model with l.
Download
here!
Tell me if you're having problems and I'll help you!