// Author: Drunkie
// Description: Draws a 3D icosahedron model (solid and wireframe)

Main();

#include <drivers\drv_gl.txt>

void Main()
{
    glSleep( 40 ); // Sleep for 40 milliseconds (Reduces fps lag)
    glClear( 0, 0, 0 ); // Clear screen

    glCoordPipe( GL_CPIPE_N1_1 ); // Set coordinate pipe to [-1 to 1] mode
    glVertexPipe( GL_VPIPE_XYZTRANSFORM ); // Set vertex pipe to xyz transformation

    glLightPos( 0, 0, -50 ); // Set the light position
    glLightColor( 255, 255, 255, 1 ); // Set the light color

    glLookAt(
        0, 0, -2.25, // Camera pos
        0, 0, 0, // Camera target
        0, 1, 0 // Camera up
    );

    // Create variable to hold curtime
    float time;
    timer time;

    // Create perspective and matrix transformations
    glPerspective( 30, 1, 1, 20 ); // FOV, ASPECT RATIO, ZNEAR, ZFAR
    glRotate( 1, 1, 0, time ); // AXIS X, Y, Z, ANGLE W
    glTranslate( 0, 0, 0 ); // TRANSLATION X, Y, Z
    glScale( 1, 1, 1, 0 ); // SCALE X, Y, Z

    glEnable( GL_VERTEX_BUFFER ); // Enable vertex buffer
    glEnable( GL_VERTEX_ZSORT ); // Enable Z sorting
    glEnable( GL_VERTEX_LIGHTING ); // Enable vertex lighting
    //glEnable( GL_VERTEX_CULLING ); // Enable face culling

    // Solid 3D polygon
    glFillMode( GL_FILL_SOLID ); // Set fillmode as solid
    glColor4( 100, 149, 237, 180 ); // Set the draw color with alpha
    glPoly3D( vertexBuffer, 20 ); // Draw 3D polygon
    glFlush(); // Flush the vertex buffer to the screen

    glDisable( GL_VERTEX_LIGHTING ); // Enable vertex lighting

    // Wireframe 3D polygon
    glLineWidth( 1 ); // Set line width of wireframe
    glFillMode( GL_FILL_WIREFRAME ); // Set fillmode as wireframe
    glColor4( 255, 255, 255, 255 ); // Set the draw color with alpha
    glPoly3D( vertexBuffer, 20 ); // Draw 3D polygon
    glFlush(); // Flush the vertex buffer to the screen

    glExit(); // Exit
}

// The vertex data for our model
vertexBuffer:
db 0,0,1; db 0,0.9,0.5; db 0.9,0.3,0.4;
db 0,0,1; db -0.9,0.3,0.4; db 0,0.9,0.5;
db 0,0,1; db -0.5,-0.7,0.4; db -0.9,0.3,0.4;
db 0,0,1; db 0.5,-0.7,0.4; db -0.5,-0.7,0.4;
db 0,0,1; db 0.9,0.3,0.4; db 0.5,-0.7,0.4;
db 0.9,-0.3,-0.4; db 0.9,0.3,0.4; db 0.5,0.7,-0.4;
db 0,0.9,0.5; db 0.5,0.7,-0.4; db 0.9,0.3,0.4;
db 0,0.9,0.5; db -0.5,0.7,-0.4; db 0.5,0.7,-0.4;
db 0,0.9,0.5; db -0.9,0.3,0.4; db -0.5,0.7,-0.4;
db -0.9,-0.3,-0.4; db -0.5,0.7,-0.4; db -0.9,0.3,0.4;
db -0.9,-0.3,-0.4; db -0.9,0.3,0.4; db -0.5,-0.7,0.4;
db -0.9,-0.3,-0.4; db -0.5,-0.7,0.4; db 0,-0.9,-0.5;
db 0.5,-0.7,0.4; db 0,-0.9,-0.5; db -0.5,-0.7,0.4;
db 0.5,-0.7,0.4; db 0.9,-0.3,-0.4; db 0,-0.9,-0.5;
db 0.5,-0.7,0.4; db 0.9,0.3,0.4; db 0.9,-0.3,-0.4;
db 0,0,-1; db 0,-0.9,-0.5; db 0.9,-0.3,-0.4;
db 0,0,-1; db 0.9,-0.3,-0.4; db 0.5,0.7,-0.4;
db 0,0,-1; db 0.5,0.7,-0.4 db -0.5,0.7,-0.4;
db 0,0,-1; db -0.5,0.7,-0.4; db -0.9,-0.3,-0.4;
db 0,0,-1; db -0.9,-0.3,-0.4; db 0,-0.9,-0.5;
