// Author: Drunkie
// Description: Draws a never ending tunnel in 3D!

Main();

#include <drivers\drv_gl.txt>

void Main()
{
    glSleep( 60 ); // Sleep for 60 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( -1, -1, -1 ); // Set the light position
    glLightColor( 255, 255, 255, 1.25 ); // Set the light color

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

    // Loop and draw 4 models
    for (i = 0; i < 4; i++)
    {
        // Set translations for each model
        timer zTranslate;
        zTranslate *= -16;
        mod zTranslate,16;
        zTranslate += (i * 16);

        // Create perspective and matrix transformations
        glPerspective( 8, 1, 0.4, 20 ); // FOV, ASPECT RATIO, ZNEAR, ZFAR
        glRotate( 0, 0, 0, 0 ); // AXIS X, Y, Z, ANGLE W
        glTranslate( 0, 0, zTranslate ); // TRANSLATION X, Y, Z
        glScale( 1.2, 1, 8 ); // 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( 255, 255, 255, 150 ); // Set the draw color with alpha
        glPoly3D( VertexBuffer, 12 ); // Draw 3D polygon
        glFlush(); // Send our vertex buffer to screen

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

    glExit(); // Exit
}

float i;
float zTranslate;

vertexBuffer:
db 1,1,-1; db -1,1,-1; db 1,1,1;
db -1,1,-1; db -1,1,1; db 1,1,1;
db 1,1,-1; db 1,1,1; db 1,-1,-1;
db 1,-1,-1; db 1,1,1; db 1,-1,1;
db -1,1,-1; db -1,-1,-1; db -1,1,1;
db -1,-1,-1; db -1,-1,1; db -1,1,1;
db 1,-1,-1; db 1,-1,1; db -1,-1,-1;
db -1,-1,-1; db 1,-1,1; db -1,-1,1;
