rendered paste body#include <stdio.h>#include <stdlib.h>#include <math.h>#include <GL/glut.h>#include "ppm_canvas.h"// globalsint width, height;float last_x, last_y;int paint_state;canvas_t canvas;// display callback functionvoid cb_display(void) { // Do nothing glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(10,5, 0); glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 1.0); glVertex2f(1.0, 1.0); glEnd(); glFlush();}void cb_mouse(int button, int state, int x, int y) { if(button == GLUT_LEFT_BUTTON) switch(state){ case GLUT_DOWN: { printf("CLICKDOWN(%d, %d)\n", x, y); }break; }}void cb_motion(int x, int y) { }void cb_keyboard(unsigned char key, int x, int y) { switch (key) { case 'q': exit(0); break; case 'c': { glClear(GL_COLOR_BUFFER_BIT); glClearColor(0, 0, 0, 0); glFlush(); }break; } // end switch}void cb_reshape(int w, int h) { width = w; height = h; glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, w, 0, h); glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush();}int main(int argc, char **argv) { glutInit(&argc, argv); if(argc == 2) { if(ppmLoadCanvas(argv[1], &canvas) < 0) { printf("Failed to open: %s!\n", argv[1]); exit(-1); } else printf("Loaded: %s\n", argv[1]); } else { printf("Usage: Lab1 input\n"); exit(-1); } height = canvas.height; width = canvas.width; printf("Height = %d Width = %d\n", canvas.height, canvas.width); glutInitWindowSize(height, width); glutInitDisplayMode(GLUT_DEPTH | GLUT_RGBA); glutCreateWindow("Paint My Wagon"); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0,0,0,0); glutDisplayFunc(cb_display); glutMouseFunc(cb_mouse); glutMotionFunc(cb_motion); glutKeyboardFunc(cb_keyboard); glutReshapeFunc(cb_reshape); glutMainLoop(); return 0;}