

#include "Mode_SimpleModelDisplay.h"
using namespace iglu;

// Our main window (created in main.cpp)
extern IGLUMultiDisplayWindow::Ptr    myWin;

// Other stuff common between display modes that was initialized in main.cpp
extern IGLUOBJReader::Ptr      objCow;   // Our cow model
extern IGLUTrackball::Ptr	   ball;     // Our trackball 

// The data needed inside this display mode
IGLUShaderProgram::Ptr         simpleCowShader = 0;

IGLUFloat   cowTranslate ( 3, IGLURange<float>(2,11), 0.1,   "Distance to object" );
IGLUFloat   cowScale     ( 1, IGLURange<float>(0.2,3), 0.05, "Object scale" );

void SimpleModelDisplay::Display( void )
{
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	simpleCowShader->Enable(); 
		simpleCowShader["modelview"] = IGLUMatrix4x4::Translate( 0, 0, -cowTranslate ) * 
			                           IGLUMatrix4x4::Scale( cowScale ) * 
			                           ball->GetMatrix();
		objCow->Draw( simpleCowShader ); 
	simpleCowShader->Disable(); 
}


// Initialize variables and stuff needed for our simple model display
void SimpleModelDisplay::Initialize( int trackNum )
{
	// Add user interaction variables to the widget window
	myWin->AddWidget( trackNum, &cowTranslate );
	myWin->AddWidget( trackNum, &cowScale );

	// Now create our shader from these strings
	simpleCowShader = new IGLUShaderProgram( "shaders/simpleCowDraw.vert.glsl", 
		                                     "shaders/simpleCowDraw.frag.glsl" );
	simpleCowShader["project"] = IGLUMatrix4x4::Perspective( 60, 1, 0.5, 20 );
}