
#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;

// A simple texture we'll load from a file
IGLUTexture::Ptr       tex2D = 0;

// A simple framebuffer object (e.g., render-to-texture)
IGLUFramebuffer::Ptr   fbo;



void display ( void )
{
	// Draw our texture once, flipped in Y (to make the image right-side up)
	fbo->Bind();
		IGLUDraw::Fullscreen( tex2D, IGLU_DRAW_FLIP_Y ); 
	fbo->Unbind();

	// Now draw our output from the first IGLUDraw::Fullscreen() call by
	//    flipping it in the X axis.
	IGLUDraw::Fullscreen( fbo[0], IGLU_DRAW_FLIP_X ); 

	// Swap OpenGL front/back buffers to display what we just drew.
	glutSwapBuffers();
}


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

void idle ( void )
{
	glutPostRedisplay();
}

int main(int argc, char** argv)
{
	// Standard OpenGL/GLUT setup
	glutInit(&argc, argv);
	glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
	glutInitWindowSize( 512, 512 );
	glutInitWindowPosition( 20, 20 );
	glutCreateWindow( "Basic IGLU Texture Loader" );
	glewInit();
	glutDisplayFunc( display );
	glutIdleFunc( idle );
	glutKeyboardFunc( keys );

	// Load a simple texture
	printf("(+) Loading texture...\n" );
	tex2D = new IGLUTexture2D( "test.ppm" );

	// Create an IGLUFramebuffer.  This can be done with new(), but this
	//    is slightly complex, so the Create() methods help simplify this
	printf("(+) Creating renderable texture...\n");
	fbo   = IGLUFramebuffer::Create( GL_RGBA8, 512, 512 );

	// Start the GLUT interaction loop
	glutMainLoop();
	return 0;
}
