
#include <GL/glew.h>
#include <stdio.h>

// All headers are automatically included from "iglu.h"
#include "iglu.h"

// IGLU classes and constants are all inside the iglu namespace.
using namespace iglu;

// This is a pointer to a IGLUTexture!  Declare pointers with the syntax
//    for "IGLUClass::Ptr myPtr;" rather than "IGLUClass *myPtr;" for ALL
//    IGLU classes!
IGLUTexture::Ptr tex2D = 0;

void display ( void )
{
	// Grab the next image in the video
	tex2D->Update();

	// Use IGLU built-in function to display the rendered texture as full-screen image
	//     Because of the coordinate system of PPM files versus OpenGL, we need to 
	//     flip the Y-coordinate of the image for it to be right-side up.
	IGLUDraw::Fullscreen( tex2D, IGLU_DRAW_FLIP_Y ); 
}


void keys(unsigned char key, int x, int y)
{
	// Exit whenever any key is pressed
	exit(-1);
}


int main(int argc, char** argv)
{
	// Create an IGLU window.  This window type is based on the FLTK library.
	IGLUWindow *myWin = new IGLUWindow( 512, 512, "Basic IGLU Video Loader" );
	myWin->SetWindowProperties( IGLU_WINDOW_NO_RESIZE |	
								IGLU_WINDOW_DOUBLE |
								IGLU_WINDOW_REDRAW_ON_IDLE |
								IGLU_WINDOW_W_FRAMERATE );
	myWin->SetDisplayCallback( display );            
	myWin->SetIdleCallback( IGLUWindow::NullIdle );
	myWin->SetKeyboardCallback( keys );
	myWin->CreateWindow( argc, argv );

	// Load the texture with IGLU
	tex2D = new IGLUVideoTexture2D( "../../CommonSampleFiles/videos/buckBunnyVideo.DivX.avi", IGLU_REPEAT_VIDEO );

	// Start the FLTK interaction loop
	IGLUWindow::Run();
	return 0;
}
