
#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 )
{
	// 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 ); 

	// 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 the texture with IGLU
	printf("(+) Loading texture...\n" );
	tex2D = new IGLUTexture2D( "test.ppm" );

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