/*************************************************************************
** commonInitialization.cpp                                             **
** --------------------------                                           **
**                                                                      **
** I envision this source file containing all the initialization code   **
**    needed to create common data structures and load common resources **
**    used in this program.                                             **
**                                                                      **
** After executing main(), the next time the developer gets control     **
**    back from IGLU will be in the common initialization routine (here **
**    the OpenGLInitialization() function).  After finishing this       **
**    routine, the display modes' Initialize() methods will be called.  **
**    This means anything needed by these routines should be created    **
**    in this common initialization function.                           **
**                                                                      **
** Chris Wyman (04/06/2012)                                             **
*************************************************************************/

#include "projectIncludes.h"

// A global data structure containing all shared data for this program
extern RenderingData *data;

// The window callback guaranteed to be called *after* OpenGL initialization,
//    but before the initialization functions of our individual display modes.
void OpenGLInitialization( void *winPtr )
{	
	// Create our global rendering data structure
	data        = new RenderingData();
	data->fbo   = new FrameBufferData();
	data->geom  = new ModelData();
	data->glsl  = new ShaderData();
	data->mat   = new MatrixData();
	data->tex   = new TextureData();
	data->ui    = new UserInterfaceData();
	data->vao   = new VertexArrayData();
	data->param = new SceneParameterData();
	data->win   = (IGLUMultiDisplayWindow *)winPtr;

	// Load common geometry files
	data->geom->cornellBox  = new IGLUOBJReader( "../../CommonSampleFiles/Models/testBox.obj" );
	data->geom->cow         = new IGLUOBJReader( "../../CommonSampleFiles/Models/cow.obj", IGLU_OBJ_UNITIZE );
	IGLUOBJMaterialReader::FinalizeMaterialsForRendering();

	// Create a virtual trackball
	data->ui->ball  = new IGLUTrackball( data->win->w(), data->win->h() );

	// Set up some basic scene data consistent across all rendering modes
	data->param->lightPos = vec3(2.78,5.25,2.795);
	data->param->eyePos   = vec3(2.78, 2.73, -8.00);
}
