#include "StdAfx.h"
#include "SplashScreen.h"

#include "OGLrendrer.h"

SplashScreen::SplashScreen(char *file, unsigned int timerTicks_)
{
	fileName = new char[strlen(file) +1];
	memset(fileName, 0, strlen(file)+1);
	strcpy(fileName, file);
	texture = 0;
	timerTicks = timerTicks_;
	ticksElapsed = 0;
}


SplashScreen::~SplashScreen(void)
{
	delete[] fileName;
}

void 
SplashScreen::draw(OGLrendrer *ogl)
{
	if(!texture)
	{
		texture = ogl->loadRawTex(fileName, 1024, 768, 3);
		//texture = ogl->loadPngTex("Splash1.png");
	}

	void(__stdcall* glMultiTexCoord2dARB)(GLenum, double,double)=(void(__stdcall*)(GLenum,double,double))ogl->getGlProcAddress("glMultiTexCoord2dARB");
	
	glBindTexture(GL_TEXTURE_2D, texture);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, 1000, 1000, 0, 0, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glBegin(GL_QUADS);
		glMultiTexCoord2dARB(GL_TEXTURE0_ARB,0.0,0.0); glVertex2f(1, 1);
		glMultiTexCoord2dARB(GL_TEXTURE0_ARB,1.0,0.0); glVertex2f(999, 1);
		glMultiTexCoord2dARB(GL_TEXTURE0_ARB,1.0,1.0); glVertex2f(999, 999);
		glMultiTexCoord2dARB(GL_TEXTURE0_ARB,0.0,1.0); glVertex2f(1, 999);
	glEnd();
	glMatrixMode (GL_MODELVIEW);
}

void 
SplashScreen::resetTimer()
{
	ticksElapsed = 0;
}

bool 
SplashScreen::hasTimerExpired()
{
	if(ticksElapsed >= timerTicks)
		return true;
	return false;
}

void 
SplashScreen::tick()
{
	ticksElapsed++;
}