rendered paste body//#include "stdafx.h"#include <assert.h>#include <stdio.h>#include <stdlib.h>#include <time.h>#include <math.h>#include <ctype.h>#include <GL/glut.h>struct Color{ float r, g, b;};struct Vertice{ int x; int y; struct Color color; struct Vertice *next;};GLubyte solido[128] ={ 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF};GLubyte cuadros[128] ={ 0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F, 0xF0,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0, 0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x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, 0x8F,0x8F,0x8F,0x8F, 0xC7,0xC7,0xC7,0xC7, 0xE3,0xE3,0xE3,0xE3, 0xF1,0xF1,0xF1,0xF1, 0xF8,0xF8,0xF8,0xF8, 0x7C,0x7C,0x7C,0x7C, 0x3E,0x3E,0x3E,0x3E, 0x1F,0x1F,0x1F,0x1F, 0x8F,0x8F,0x8F,0x8F, 0xC7,0xC7,0xC7,0xC7, 0xE3,0xE3,0xE3,0xE3, 0xF1,0xF1,0xF1,0xF1, 0xF8,0xF8,0xF8,0xF8, 0x7C,0x7C,0x7C,0x7C, 0x3E,0x3E,0x3E,0x3E, 0x1F,0x1F,0x1F,0x1F, 0x8F,0x8F,0x8F,0x8F, 0xC7,0xC7,0xC7,0xC7, 0xE3,0xE3,0xE3,0xE3, 0xF1,0xF1,0xF1,0xF1, };struct Poligono{ int ancho; GLubyte *patron; struct Vertice *primero; struct Poligono *next;};GLubyte *patron = cuadros;struct Poligono *primera = NULL;struct Poligono *polActual = NULL;//struct Vertice* primero = NULL;struct Vertice posicionRaton;struct Color color;int anchoVentana = 400, altoVentana = 400;int grosorLinea = 1;int finalizado = 0;void inicializar (void);void representarEscena ();void redimensionarEscena (int, int);void addVertice (int boton, int estado, int x, int y);void seguirCursor (int x, int y);void teclas (unsigned char tecla, int x, int y);int main (int argc, char **argv){ glutInit (&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition (200, 200); glutInitWindowSize (anchoVentana, altoVentana); glutCreateWindow ("Funciones"); inicializar (); glutDisplayFunc (representarEscena); glutReshapeFunc (redimensionarEscena); glutKeyboardFunc (teclas); glutPassiveMotionFunc (seguirCursor); glutMouseFunc (addVertice); glutMainLoop (); return 0;}void redimensionarEscena (int ancho, int alto){ anchoVentana = ancho; altoVentana = alto; glViewport (0, 0, ancho, alto); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, ancho, 0, alto); glMatrixMode (GL_MODELVIEW);}void inicializar (void){ glClearColor (1.0, 1.0, 1.0, 1.0); color.r = 1; color.g = 0; color.b = 0; srandom (time (NULL)); glEnable(GL_POLYGON_STIPPLE);}void representarEscena (){ glClear (GL_COLOR_BUFFER_BIT); struct Vertice *currVertice; struct Poligono *poligono = primera; while (poligono) { currVertice = poligono->primero; glLineWidth(poligono->ancho); glPolygonStipple(poligono->patron); glBegin (GL_POLYGON); while (currVertice) { glColor3f (currVertice->color.r, currVertice->color.g, currVertice->color.b); glVertex3f (currVertice->x, currVertice->y, 0); currVertice = currVertice->next; } poligono=poligono->next; if(poligono == NULL) { glColor3f (posicionRaton.color.r, posicionRaton.color.g, posicionRaton.color.b); glVertex3f (posicionRaton.x, posicionRaton.y, 0); glEnd(); } glEnd(); } glutSwapBuffers ();}void addVertice (int boton, int estado, int x, int y){ struct Vertice *curr = NULL; struct Poligono *linea = NULL; y = altoVentana - y; if (boton == GLUT_LEFT_BUTTON && estado == GLUT_DOWN) { finalizado = 0; if (polActual == NULL) { primera = (struct Poligono *) malloc (sizeof (struct Poligono)); polActual = primera; primera->primero = NULL; primera->next = NULL; } if (polActual->primero == NULL) { polActual->ancho = grosorLinea; polActual->primero = (struct Vertice *) malloc (sizeof (struct Vertice)); polActual->primero->x = x; polActual->primero->y = y; polActual->primero->color.r = color.r; polActual->primero->color.g = color.g; polActual->primero->color.b = color.b; polActual->primero->next = NULL; } else { curr = polActual->primero; while (curr->next != NULL) curr = curr->next; curr->next = (struct Vertice *) malloc (sizeof (struct Vertice)); curr->next->x = x; curr->next->y = y; curr->color.r = color.r; curr->color.g = color.g; curr->color.b = color.b; curr->next->next = NULL; } } if (boton == GLUT_RIGHT_BUTTON && estado == GLUT_DOWN) { if(!finalizado) { finalizado = 1; polActual->next = (struct Poligono *) malloc (sizeof (struct Poligono)); polActual = polActual->next; polActual->primero = NULL; polActual->next = NULL; } else { linea = primera; while(linea) { curr = linea->primero; while(curr) { linea->primero = linea->primero->next; free(curr); curr = linea->primero; } primera=primera->next; free(linea); linea = primera; } polActual = NULL; } } glutPostRedisplay ();}void seguirCursor (int x, int y){ posicionRaton.x = x; posicionRaton.y = altoVentana - y; posicionRaton.color = color; if(polActual) polActual->patron = patron; glutPostRedisplay ();}void teclas (unsigned char tecla, int x, int y){ switch (tecla) { case 'q': case 'Q': exit (EXIT_SUCCESS); break; case 'r': case 'R': color.r = 1; color.g = 0; color.b = 0; break; case 'g': case 'G': color.r = 0; color.g = 1; color.b = 0; break; case 'B': case 'b': color.r = 0; color.g = 0; color.b = 1; break; case 's': case 'S': patron = solido; break; case 'C': case 'c': patron = cuadros; break; case 'V': case 'v': patron = verticales; break; case 'H': case 'h': patron = horizontales; break; case 'O': case 'o': patron = oblicuas; break; default: if (isdigit (tecla)) grosorLinea = tecla - 48; } glutPostRedisplay ();}