Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: C | Size: 2.40 KB | Hits: 61 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. /* Rafael de Luna Galdino RA 072135 , UNICAMP-2010 */
  2.  
  3. #include <stdlib.h>
  4. #include <GL/glut.h>
  5.  
  6. //coordenada y
  7. GLint y1 = 1;
  8. GLint height = 80;
  9.  
  10.  
  11. GLint x = 11;
  12. GLint inc = 5;
  13.  
  14. int cont_numquads = 0;
  15. GLint vet_posy[10];
  16.  
  17. //condicao
  18. int inicio = 1;
  19.  
  20. int direcao[10];
  21. void init(void);
  22. void criaQuads(int x1, int y1, float corR, float corG, float corB);
  23. void display(void);
  24. void move(int passo);
  25. void keyboard(unsigned char key, int x, int y);
  26.  
  27.  
  28. int main(int argc, char** argv){
  29.   glutInit(&argc, argv);
  30.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  31.   glutInitWindowSize (180, 100);
  32.   glutInitWindowPosition (100, 100);
  33.   glutCreateWindow ("rOLAAAA");
  34.   init();
  35.   glutDisplayFunc(display);
  36.   glutKeyboardFunc(keyboard);
  37.  
  38.   glutMainLoop();
  39.   return 0;
  40. }
  41.  
  42. void init(void)
  43. {
  44.      int i;
  45.      
  46.      glClearColor(0.0, 0.0, 0.0, 0.0);
  47.      glOrtho (0, 180, 0, 100, -1 ,1);
  48.  
  49.      for (i = 0; i < 10; ++i)  
  50.      {
  51.          direcao[i] = inicio;
  52.          vet_posy[i] = 10;
  53.      }
  54. }
  55.  
  56. void display(void)
  57. {
  58.      int cont;
  59.      glClear(GL_COLOR_BUFFER_BIT);
  60.      glColor3f(1.0, 1.0, 1.0);
  61.      glLineWidth(15.0);
  62.  
  63.      // borda
  64.      glBegin(GL_LINE_LOOP);
  65.        glVertex2i(1,1);  glVertex2i(180,1);
  66.        glVertex2i(180,100); glVertex2i(1,100);
  67.      glEnd();
  68.  
  69.  
  70.      for (cont = 0; cont < 10; cont++)
  71.      {
  72.          criaQuads(x, vet_posy[cont], 0.8, 0.2, 0.8);
  73.          x = x + 15;
  74.      }
  75.      x = 11;
  76.      if (cont_numquads < 10)
  77.        cont_numquads++;
  78.  
  79.  
  80.  
  81.   glFlush();
  82.   glutSwapBuffers();
  83.  }
  84.  
  85. void criaQuads(int x, int y, float corR, float corG, float corB)
  86. {
  87.   glColor3f(corR, corG, corB);
  88.  
  89.   glBegin(GL_QUADS);
  90.     glVertex2i(x, y + 10);
  91.     glVertex2i(x + 10, y + 10);
  92.     glVertex2i(x + 10, y);
  93.     glVertex2i(x, y);
  94.   glEnd();
  95. }
  96.  
  97.  
  98.  
  99. void keyboard(unsigned char key, int x, int y){
  100.   switch (key)
  101.   {
  102.          case 27:
  103.                   exit(0);
  104.               break;
  105.          case 32:
  106.                   glutTimerFunc(50, move, 1);
  107.               break;
  108.   }
  109. }
  110.  
  111.  
  112.  
  113. void move(int passo)
  114. {
  115.   for(int cont = 0; cont < cont_numquads; cont++)
  116.   {
  117.     if (direcao[cont] == 1)
  118.        vet_posy[cont] += inc;
  119.  
  120.     if (vet_posy[cont] == height)
  121.        direcao[cont] = 0;
  122.        
  123.     if (direcao[cont] == 0)
  124.          vet_posy[cont] -= inc;
  125.  
  126.     if (vet_posy[cont] == 10)
  127.        direcao[cont] = 1;
  128.  }
  129.  
  130.  glutPostRedisplay();
  131.  glutTimerFunc(30,move, 1);
  132. }