

#include "Mode_SimpleVideoDisplay.h"
using namespace iglu;

// Our main window
extern IGLUMultiDisplayWindow::Ptr    myWin;

// The texture for this display
IGLUTexture::Ptr simple2DVideo = 0;

// A user variable to determine if we display decimal or hex values
IGLUInt  targetFramerate ( 24, IGLURange<int>(5,300),  1, "Video playback speed (fps)" );

// The timer we'll use to determine if it's time to update to the next video frame
IGLUCPUTimer::Ptr  videoTimer = 0;


void SimpleVideoDisplay::Display( void )
{
	// Update to the next video frame (if it's time)
	if ( videoTimer->GetTime() > (1000.0/targetFramerate) )
	{
		simple2DVideo->Update();  // It's time!  Update!
		videoTimer->Tick();       // Reset the timer.
	}

	// Draw the video frame onscreen
	IGLUDraw::Fullscreen( simple2DVideo, IGLU_DRAW_FLIP_Y ); 
}

// Initialize variables and stuff needed for our video display
void SimpleVideoDisplay::Initialize( int trackNum )
{
	// Load a video to play
	simple2DVideo = new IGLUVideoTexture2D( "../../CommonSampleFiles/videos/buckBunnyVideo.DivX.avi", IGLU_REPEAT_VIDEO );

	// Create a timer to control video playback
	videoTimer = new IGLUCPUTimer();
	videoTimer->Start();

	// Add widgets to the built-in UI window.  
	myWin->AddWidget( trackNum, &targetFramerate );
}


