#include "Level.h"
#include "Title.h"
#include "Globals.h"
#include "rapidxml.hpp"
#include "Rabbit.h"
#include "Wumbo-KeyboardInput.h"
#include "Wumbo-Quicky.h"
#include "FjordsSound.h"

Title::Title(Wumbo::Program *prog) : Wumbo::Scene(prog)
{
}
void Title::begin()
{
	stopAllMusic();
}
void Title::update()
{
	if (Wumbo::__quickyKeyboard->isKeyPressed(Wumbo::Key::X))
		program->setScene(new Level(program,"world",-1,-1,false,-1));
}
void Title::render()
{
	unsigned int TOPBARHEIGHT = 30;
#if PLATFORM_IOS
	if (Wumbo::Platform_iOS::iPad())
		renderer->setVirtualRenderTarget(VirtualRenderTarget(0,0,768,1024,768,1024));
	else if (Wumbo::Platform_iOS::FourInch())
		renderer->setVirtualRenderTarget(VirtualRenderTarget(0,0,320,568,320,568));
	else
		renderer->setVirtualRenderTarget(VirtualRenderTarget(0,0,320,480,320,480));
#else
	program->getRenderer()->setVirtualRenderTarget(VirtualRenderTarget(0,0,WINDOW_WIDTH*WINDOW_SCALE,WINDOW_HEIGHT*WINDOW_SCALE,WINDOW_WIDTH,WINDOW_HEIGHT));
#endif
	glClearColor(SHARECART_BLACK);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glBindTexture(GL_TEXTURE_2D,title->getTexture());
	VIEW = glm::mat4x4(1.f);//glm::lookAt(glm::vec3(10*width/2+xdist,ydist,10*width/2+zdist),glm::vec3(10*width/2,0.f,10*height/2),glm::vec3(0.f,1.f,0.f));//glm::ortho(-1.f,1.f,1.f,-1.f,-10.f,10.f);// * glm::translate(glm::mat4(1.0f), glm::vec3(-10.f,-10.f,0)) * glm::scale(glm::mat4(1.0f),glm::vec3(2.f/320.f,2.f/480.f,0.f));
	PROJ = glm::ortho(0.f,(float)WINDOW_WIDTH,(float)WINDOW_HEIGHT,0.f);
	textbatch->begin();
		textbatch->addUVTile(0,0,0,320,480,0,0xFFFFFFFF,0,0,320.f/512.f,480.f/512.f);
	textbatch->finish();
	matrixBegin();
	matrixUpload();
	textbatch->draw();

	//draw_rectangle(0,0,WINDOW_WIDTH,(WINDOW_HEIGHT-WINDOW_WIDTH)-TOPBARHEIGHT);
#if PLATFORM_IOS
	if (Wumbo::Platform_iOS::iPad())
		renderer->setVirtualRenderTarget(VirtualRenderTarget(0,0,768,1024,768,1024));
	else if (Wumbo::Platform_iOS::FourInch())
		renderer->setVirtualRenderTarget(VirtualRenderTarget(0,0,320,568,320,568));
	else
		renderer->setVirtualRenderTarget(VirtualRenderTarget(0,0,320,480,320,480));
#else
	program->getRenderer()->setVirtualRenderTarget(VirtualRenderTarget(0,(WINDOW_WIDTH+TOPBARHEIGHT)*WINDOW_SCALE,WINDOW_WIDTH*WINDOW_SCALE,(WINDOW_HEIGHT-WINDOW_WIDTH-TOPBARHEIGHT)*WINDOW_SCALE,WINDOW_WIDTH,WINDOW_HEIGHT-WINDOW_WIDTH-TOPBARHEIGHT));
#endif
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBindTexture(GL_TEXTURE_2D,tex->getTexture());
	VIEW = glm::mat4x4(1.f);//glm::lookAt(glm::vec3(10*width/2+xdist,ydist,10*width/2+zdist),glm::vec3(10*width/2,0.f,10*height/2),glm::vec3(0.f,1.f,0.f));//glm::ortho(-1.f,1.f,1.f,-1.f,-10.f,10.f);// * glm::translate(glm::mat4(1.0f), glm::vec3(-10.f,-10.f,0)) * glm::scale(glm::mat4(1.0f),glm::vec3(2.f/320.f,2.f/480.f,0.f));
	PROJ = glm::ortho(0.f,(float)WINDOW_WIDTH,(float)(WINDOW_HEIGHT-WINDOW_WIDTH)-TOPBARHEIGHT,0.f);

	draw_rectangle(0,0,WINDOW_WIDTH,(WINDOW_HEIGHT-WINDOW_WIDTH)-TOPBARHEIGHT);
	draw_text(10,10,"MORTON\r\n\r\nA game by Wade McGillis\r\n\r\n\r\nCONTROLS:\r\n\r\nArrows Keys - Move\r\n\r\nX - Talk / START GAME");
}