#include "PostProcessing.h"

int main(int argc, char **argv)
{
	IrrlichtDevice *device = createDevice(video::EDT_OPENGL,core::dimension2d< s32 >(640, 480),32);
	video::IVideoDriver *driver = device->getVideoDriver();
	scene::ISceneManager *smgr = device->getSceneManager();
	gui::IGUIEnvironment *guienv = device->getGUIEnvironment();
	device->getFileSystem()->addZipFileArchive("map-20kdm2.pk3");
	smgr->addOctTreeSceneNode(smgr->getMesh("20kdm2.bsp"));
	smgr->addCameraSceneNodeFPS();
	device->getCursorControl()->setVisible(false);

	//invert colors
//	PostProcessing *PP_Test = new PostProcessing(smgr,"Shaders/PP_GL_Invert.fx","Shaders/PP_DX_Invert.fx",video::EPST_PS_1_4,512,256);

	//build up the effect chain for bloom
	PostProcessing *PP_Test = new PostProcessing(smgr,"Shaders/PP_GL_Bloom1.fx","Shaders/PP_DX_Bloom1.fx",video::EPST_PS_1_4,512,256);
    PP_Test->setShaderParameters(0.5f);
    PostProcessing *Test2 = PP_Test->addMaterial("Shaders/PP_GL_Bloom2.fx","Shaders/PP_DX_Bloom2.fx",video::EPST_PS_2_0,128,128);
    Test2->setShaderParameters(0.01f);
    Test2 = Test2->addMaterial("Shaders/PP_GL_Bloom3.fx","Shaders/PP_DX_Bloom3.fx",video::EPST_PS_2_0,128,128);
    Test2->setShaderParameters(0.01f);
    Test2 = Test2->addMaterial("Shaders/PP_GL_Bloom4.fx","Shaders/PP_DX_Bloom4.fx",video::EPST_PS_2_0,512,256);
    Test2->setShaderParameters(0.7f);
    Test2->setSecondMap(PP_Test->getFirstMap(),video::ETC_CLAMP);

	//the main loop
	while(device->run())
	{
		 if (device->isWindowActive())
		 {
			driver->beginScene(true, true, video::SColor(255,150,180,255));

			//render the scene into the postprocessing texture
			driver->setRenderTarget(PP_Test->getFirstMap(), true, true, video::SColor(255,150,180,255));
			smgr->drawAll();
			driver->setRenderTarget(0);

			//render the effect chain
			PP_Test->renderEffect();

			guienv->drawAll();
			driver->endScene();
		  }
	}

	device->drop();
}
