#include #include int pos_x[60], pos_y[60]; int puntos = 0; void Inicializa(void) { glClearColor(1.0,1.0,1.0,0.0); // color de background blanco glColor3f(1.0f, 0.0f, 0.0f); // color de dibujo rojo glPointSize(4.0); // tamaño del punto en pixels glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0, 640.0, 0.0, 480.0); } // = = = = = = = Funciones interacción Teclado y Ratón = = = = = = void Raton(int button, int state, int x, int y) { int alto_ventana=480; if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { pos_x[puntos] = x; pos_y[puntos] = alto_ventana - y; // voltea la coordenada y puntos++; } // glutPostRedisplay(); } void PageUp_Down(int key, int x, int y) { switch(key) { case GLUT_KEY_PAGE_UP: glPointSize(8); break; case GLUT_KEY_PAGE_DOWN: glPointSize(4); break; default:break; } glutPostRedisplay(); } void Teclado(unsigned char key, int x, int y) { switch(key) { case 27: // Esc exit(0); // Salir del programa case 'r': glColor3f(1.0, 0.0, 0.0); //rojo break; case 'a': glColor3f(0.0, 0.0, 1.0); //azul break; default:break; } glutPostRedisplay(); } // = = = = = = = = = = = = Dibuja = = = = = = = = = = = = void Dibuja(void) { int i; glClear(GL_COLOR_BUFFER_BIT); // limpia la pantalla glBegin(GL_POINTS); for (i=0 ; i< puntos; i++) glVertex2i(pos_x[i], pos_y[i]); glEnd(); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); glutInitWindowSize(640,480); glutInitWindowPosition(100, 150); glutCreateWindow("Dibujando puntos"); // Registro de funciones glutDisplayFunc(Dibuja); glutMouseFunc(Raton); glutKeyboardFunc(Teclado); glutSpecialFunc(PageUp_Down); Inicializa(); glutMainLoop(); return 0; }