#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "objfile.h"
#include <mmsystem.h>
#include <assert.h>

static unsigned long m_dwLastTime=0;
unsigned long m_dwCurrentTime=0;

int Get_FPS(void)
{
	static DWORD fps_time1=GetTickCount();
	static int fps_count, fps;
	DWORD fps_time2 = GetTickCount();

	fps_count++;
	if(fps_time2-fps_time1 >= 1000)
	{
		fps_time1=GetTickCount();
		fps=fps_count;
		fps_count=0;
	}

	return fps;
}


float inittime=0;
float FPS= 0;
float currentTime=0;
float helppoheikki=0;
float taimeri=0;


UINT TextureArray[30];
OBJECT * o1;
GLint o1list;

OBJECT * o2;
GLint o2list;

OBJECT * o3;
GLint o3list;

OBJECT * o4;
GLint o4list;

OBJECT * o5;
GLint o5list;

OBJECT * o6;
GLint o6list;

OBJECT * o7;
GLint o7list;

GLint Gen3DObjectList(OBJECT * o1)
{
 int i;
 int j;

 GLint lid=glGenLists(1);
   glNewList(lid, GL_COMPILE);

    glBegin (GL_TRIANGLES);
      for(i=0;i<o1->numfaces;i++)
       {
       for(j=0;j<3;j++)
        {
          int vi=o1->faces[i].vert[j];
          int ni=o1->faces[i].norm[j];//Normal index
          int ti=o1->faces[i].tex[j];//Texture index
           glNormal3f (o1->normals[ni].x,o1->normals[ni].y,o1->normals[ni].z);
           glTexCoord2f(o1->texturecoords[ti].u,o1->texturecoords[ti].v);
           glVertex3f (o1->vertices[vi].x,o1->vertices[vi].y,o1->vertices[vi].z);
        }
       }
    glEnd ();

   glEndList();
   return lid;
};


void capFrameRate(double fps) {
    static double start = 0, diff, wait;
    wait = 1 / fps;
    diff = glfwGetTime() - start;
    if (diff < wait) {
        glfwSleep(wait - diff);
    }
    start = glfwGetTime();
}



