#include #include "ppmImage.h" #include //global image ppmImage image; /** *Sets up approriate viewport coordinates for 2D */ void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, h, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } /** * display callback function */ void display(void){ glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(image.GetWidth(), image.GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, image.getPixels()); glFlush(); /* Single buffered, so needs a flush. */ } /** * Main entry point */ int main(int argc, char *argv[]){ if(argc != 2) { // Take path to image as runtime arg std::cerr << "Usage: ./a.out \n"; exit(1); } if( !image.readFile(argv[1]) ) { // Read the image std::cerr << "Failed to read image\n"; exit(1); } image.writeFile("writeTest.ppm"); // Write the image to disk // Initialize glut glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(image.GetWidth(), image.GetHeight()); glutInitWindowPosition(100,100); glutCreateWindow("ImageLoading example"); glutDisplayFunc(display); glutReshapeFunc(reshape); //for GL speed-ups glDisable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); // For fixing the 4 byte boundary issue (Thanks Thomas Hofler) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glutMainLoop(); // Give control to glut exit(0); }