//--------------------------------------------------------------------------------------
// Name: GenOrthoMatrix
// Desc: Generate a orthogonal matrix
//--------------------------------------------------------------------------------------
void GLCVUtils::GenOrthoMatrix(float left,float right,float bottom,float top,float zNear,float zFar, float *m)
{	
	float tx=-(right+left)/(right-left);
	float ty=-(top+bottom)/(top-bottom);
	float tz=-(zFar+zNear)/(zFar-zNear);
	LoadIdentityMatrix4x4 (m);
	m[0]=2/(right-left);
	m[5]=2/(top-bottom);
	m[10]=-2/(zFar-zNear);	
	m[12]=tx;
	m[13]=ty;
	m[14]=tz;

}
int preRender()
{

	// load and compiler vertex/fragment shaders.
	LoadShaders("resources/shaders/vs_phong.vert", "resources/shaders/fs_phong.frag", g_hPShaderProgram);
	LoadShaders("resources/shaders/vs_texture.vert", "resources/shaders/fs_texture.frag", g_hTXShaderProgram );

	//init assImp stream
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	aiAttachLogStream(&stream);

	//write stream to log 
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	aiAttachLogStream(&stream);
	
	ilInit(); //if you use textures, do this.

	if (g_hPShaderProgram  != 0)
	{
		projMatrixLoc= glGetUniformLocation(g_hPShaderProgram, "projMatrix");
		viewMatrixLoc= glGetUniformLocation(g_hPShaderProgram, "viewMatrix");
	} else {
		printf("phong shader program not compiled/linked\n");
		return 1;
	}
	if (g_hTXShaderProgram  != 0)
	{
		projMatrixLoc= glGetUniformLocation(g_hTXShaderProgram, "projMatrix");
		viewMatrixLoc= glGetUniformLocation(g_hTXShaderProgram, "viewMatrix");
	} else {
		printf("Texture shader program not compiled/linked\n");
		return 1;
	}

	// Build a perspective projection matrix. 
	PerspectiveMatrix4x4 ( matProj, 70.f, 1.3333f, 0.1f, 200.f);
	LoadIdentityMatrix4x4 (matModelView);
	TranslateMatrix4x4 (matModelView, 0, 0, -20.0f); //(0, -2, -10)
	RotateMatrix4x4 (matModelView, -90, X_AXIS);
	RotateMatrix4x4 (matModelView, -90, Y_AXIS);
	return 0;

}