View Single Post
  #2 (permalink)  
Old 03-16-2008, 06:50 AM
MrPickle's Avatar
MrPickle MrPickle is offline
Sr. Programmer
Join Date: Nov 2007
Location: England, Lincolnshire
Posts: 303
iTrader: (0)
MrPickle is on a distinguished roadMrPickle is on a distinguished roadMrPickle is on a distinguished road
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

Code:
    }
}
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!

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by MrPickle : 03-16-2008 at 07:18 AM.
Reply With Quote
The Following User Says Thank You to MrPickle For This Useful Post:
ccoonen (03-16-2008)