#include "OnlyOneProgram.h"

Wumbo::Program *WUMBOFRAMEWORK_GETNEWPROGRAM()
{
	return new OnlyOneProgram();
}

#include "Wumbo-Header.h"
#include "Wumbo-Scene.h"
#include "Wumbo-InputManager.h"
#include "Wumbo-KeyboardInput.h"
#include "Wumbo-Renderer.h"
#include "Wumbo-RenderTarget.h"
#include "GM.h"
#include "Wumbo-Functions.h"

#include "Wumbo-Shader.h"
#include "Wumbo-ShaderBuilder.h"
Wumbo::Shader *megaShader;

#include "scTitle.h"
#include "Wumbo-Sound.h"

void OnlyOneProgram::begin() 
{
	Wumbo::ShaderBuilder builder;
	builder.loadVertexShader(Wumbo::BundleResource("Shader.vsh"));
	builder.loadFragmentShader(Wumbo::BundleResource("Shader.fsh"));
	builder.addAttrib(Wumbo::WumboVertexAttribPosition, "position");
	builder.addAttrib(Wumbo::WumboVertexAttribColor, "color");
	builder.addAttrib(Wumbo::WumboVertexAttribTexCoord0, "texcoord0");
	builder.addUniform("supermatrix");
	megaShader = builder.generate();
	if (megaShader == NULL)
	{
		megaShader = new Wumbo::Shader();
		printf("megashader is null");
	}
	program = megaShader->getProgramID();
	printf("program is %i\n",program);
	inputManager = new Wumbo::InputManager(this);
	inputManager->initialize();
	inputManager->setReceiveKeyboardUpdates(true);
	inputManager->setReceiveXbox360Updates(true);
	inputManager->setReceiveTouchUpdates(true);
	inputManager->setReceiveAccelerometerUpdates(true);
	
	renderer = new Wumbo::Renderer(this);
	renderer->setRotation(Wumbo::ScreenRotation_DOWN);
	renderer->resetVirtualRenderTarget();
	setAssignedFrameRate(60);

	renderer->setTitle("You Only Get One");
	Wumbo::Program::begin();
	GM::gm_wumbo_init(this);

	renderer->setDisplaySize(1024,768);

	scene = new scTitle(this);
	scene->begin();
	Wumbo::Sound *snd = new Wumbo::Sound();
	snd->load("sound.ogg",1);
	snd->loop();


}

void OnlyOneProgram::render()
{
	glUseProgram(program);
	glClearColor(0.f,1.f,0.f,1.f);// CLEAR BLUE
	glClear(GL_COLOR_BUFFER_BIT);

	scene->render();
	
}

void OnlyOneProgram::update()
{ 
	Wumbo::Program::update();
	scene->update();
}

void OnlyOneProgram::end()
{
	Wumbo::Program::end();
#if PLATFORM_PC
	delete sfmlwindow;
#endif
}