#include<nds.h> 
#include <stdio.h>
#include <time.h>
const char* months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
void DrawQuad(float x, float y, float width, float height) 
{ 
        glBegin(GL_QUADS); 
        glVertex3f(x - width / 2, y, 0); 
        glVertex3f(x + width / 2, y, 0); 
        glVertex3f(x  + width / 2, y  + height, 0); 
        glVertex3f(x - width / 2, y  + height, 0); 
        glEnd(); 
} 
int main() 
{    
        int hours, seconds, minutes; 
        
        lcdMainOnTop(); 
        
        videoSetMode(MODE_0_3D); 
        
        glInit();
        
        glViewport(0,0,255,191); 
        
        glClearColor(0,0,0,31); 
        glClearDepth(0x7FFF); 
        consoleDemoInit();
        
 
        
        
        
        glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); 
        
        
        glMatrixMode(GL_MODELVIEW); 
        glLoadIdentity(); 
        
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(70, 256.0 / 192.0, 0.1, 100);
        gluLookAt(      0.0, 0.0, 3.0,          
                                0.0, 0.0, 0.0,          
                                0.0, 1.0, 0.0);         
        
        while (1) 
        { 
                time_t unixTime = time(NULL);
                struct tm* timeStruct = gmtime((const time_t *)&unixTime);
                
                hours = timeStruct->tm_hour;
                minutes = timeStruct->tm_min;
                seconds = timeStruct->tm_sec;
                
                
                glPushMatrix();    
                
                glColor3f(0,0,1); 
                glRotateZ(-seconds * 360 / 60); 
                glTranslatef(0,1.9,0); 
                DrawQuad(0,0,.2,.2); 
                
                glPopMatrix(1); 
                
                glPushMatrix();    
                
                glColor3f(0,1,0); 
                glRotateZ(-minutes * 360 / 60); 
                DrawQuad(0,0,.2,2); 
                
                glPopMatrix(1); 
                
                glPushMatrix();    
                
                glColor3f(1,0,0); 
                glRotateZ(-hours * 360 / 12); 
                DrawQuad(0,0,.3,1.8); 
                
                glPopMatrix(1);
                printf("\x1b[2J%02i:%02i:%02i", hours, minutes, seconds);
                printf("\n%s %i %i", months[timeStruct->tm_mon], timeStruct->tm_mday, timeStruct->tm_year +1900);
                
                
                glFlush(0);
                
                swiWaitForVBlank();
        } 
        return 0; 
}