Documentos de Académico
Documentos de Profesional
Documentos de Cultura
c 11/6/2020 11:19
1
2
3 void tecladoEspecial(int tecla, int x, int y) {
4 switch(tecla) {
5 case GLUT_KEY_UP : posy++;break;
6 case GLUT_KEY_DOWN : posy--;break;
7 case GLUT_KEY_RIGHT : posx++;break;
8 case GLUT_KEY_LEFT : posx--;break;
9 case GLUT_KEY_PAGE_UP : esc=esc*1.01;break;
10 case GLUT_KEY_PAGE_DOWN : esc=esc*0.99;break;
11 case GLUT_KEY_F1 : figura=1;break;
12 case GLUT_KEY_F2 : figura=2;break;
13 case GLUT_KEY_F3 : figura=3;break;
14 case GLUT_KEY_F4 : figura=4;break;
15 case GLUT_KEY_F5 : alterna_movimiento();break;
16 case GLUT_KEY_F6 : alterna_pantalla();break;
17 case GLUT_KEY_F9 : luz=0;glPolygonMode(GL_FRONT_AND_BACK,G
18 case GLUT_KEY_F10 : luz=0;glPolygonMode(GL_FRONT_AND_BACK,
19 case GLUT_KEY_F11 : luz=1;glPolygonMode(GL_FRONT_AND_BACK,
20 }
21 glutPostRedisplay();
22 }
23
24 void texto(int x, int y, char *palabra) {
25 int i;
26 glColor3f(0,0,0);
27 glRasterPos2f(x, y);
28 for (i = 0; palabra[i]; i++)
29 glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, palabra[i]);
30 }
31
32 void desocupado() {
33 if (movimiento==1) {
34 angulo=angulo+0.3;
35 if (angulo>=360)
36 angulo=0;
37 glutPostRedisplay();
Page 1 of 7
siete.c 11/6/2020 11:19
38 }
39 }
40 #include <GL/glut.h>
41 #include <stdio.h>
42 #include <string.h>
43 #define ancho 640
44 #define alto 480
45 #define profundidad 500
46
47 void dibuja();
48 void ejes();
49 void tecladoNormal(unsigned char tecla, int x, int y);
50 void tecladoEspecial(int tecla, int x, int y);
51 void texto(int x, int y, char *palabra);
52 void desocupado();
53 void redimensionado(int width, int height);
54 void luces();
55 void crear_menu();
56 void menu(int opcion);
57 void menupoligono(int opcion);
58 void menutipo(int opcion);
59 void alterna_movimiento();
60 void alterna_pantalla();
61 void mouse(int bouton,int estado,int x,int y);
62 void movimiento_mouse(int x,int y);
63 void texto_terminal(char *cmd);
64
65 int posx=0, posy=0;
66 float angulo=0;
67 float esc=1;
68 unsigned int figura=1;
69 GLfloat material_ambient[] = {0.05, 0.05, 0.05, 1.0f};
70 GLfloat material_diffuse[] = { 0.8, 0.0, 0.0, 1.0f};
71 GLfloat material_specular[] = {0.9, 0.8, 0.8, 1.0f};
72 GLfloat luz_ambient[] = { 0.75, 0.75, 0.75, 0.0 };
73 GLfloat luz_diffuse[] = { 1.0, 1.0, 1.0, 0.0 };
74 GLfloat luz_specular[] = { 1.0, 1.0, 1.0, 0.0 };
Page 2 of 7
siete.c 11/6/2020 11:19
Page 3 of 7
siete.c 11/6/2020 11:19
112 glutReshapeFunc(redimensionado);
113 glutMouseFunc(mouse);
114 glutMotionFunc(movimiento_mouse);
115 glutMainLoop();
116 return 0;
117 }
118
119 void dibuja() {
120 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPT
121 ejes();
122 luces();
123 glPushMatrix();
124 glTranslatef(posx, posy, 0);
125 glRotatef(anguloy,1.0,0.0,0.0);
126 glRotatef(angulox,0.0,1.0,0.0);
127 glRotatef(angulo, 1, 0, 0);
128 glRotatef(angulo, 0, 1, 0);
129 glRotatef(angulo, 0, 0, 1);
130 glScalef(esc, esc, esc);
131 glColor3f(1, 0, 0);
132 if(luz==1)
133 glEnable(GL_LIGHTING);
134 switch(figura) {
135 case 1: glutSolidTorus(20, 80, 18, 18);break;
136 case 2: glutSolidSphere(100, 18, 18);break;
137 case 3: glutSolidCone(50, 200, 18, 18);break;
138 case 4: glutSolidCube(100); break;
139 case 5: glutSolidTeapot(120);break;
140 }
141 glDisable(GL_LIGHTING);
142 glPopMatrix();
143 glutSwapBuffers();
144 }
145
146 void ejes() {
147 glColor3f(0.9, 0.9, 0.9);
148 glBegin(GL_LINES);
Page 4 of 7
siete.c 11/6/2020 11:19
Page 5 of 7
siete.c 11/6/2020 11:19
Page 6 of 7
siete.c 11/6/2020 11:19
223 }
224
225
Page 7 of 7