home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 49 / cda49.iso / VNULabs / Test / Test.c next >
Encoding:
C/C++ Source or Header  |  2000-07-01  |  3.8 KB  |  147 lines

  1. // ============================================================
  2. //   LeaRNWaRe code by CROM / Spanish  Lords 
  3. //                            - since 1993 -
  4. //
  5. //   Objetivo   : Ejemplo de manejo de la libreria aux de OpenGL
  6. //   Autor      : Pedro Ant≤n Alonso. crom@ergos.es
  7. //   Plataforma : Windows 95/98/NT/2000
  8. //   Compilador : Visual C++ 6.0
  9. //   
  10. // ============================================================
  11. #include <windows.h>
  12. #include <math.h>      // Para calcular los senos y cosenos
  13. #include <gl\gl.h>    // Libreria OpenGL
  14. #include <gl\glaux.h> // Libreria AUX de OpenGL
  15.  
  16. //
  17. // Variables globales.
  18. // -------------------
  19. //
  20. // Rotacion de cada uno de los anillos de la escena.
  21. //
  22. GLfloat         Rotacion1 = 0.0;
  23. GLfloat         Rotacion2 = 0.0;
  24. GLfloat         Rotacion3 = 0.0;
  25. //
  26. // Definici≤n de las tres luces que intervienen en la escena
  27. //
  28. static float    LuzRoja     [4] = {  1.0,  0.0,  0.0, 1.0 };
  29. static float    PosLuzRoja  [4] = {  1.0,  1.0,  1.0, 0.0 };
  30. static float    LuzVerde    [4] = {  0.0,  0.3,  0.0, 1.0 };
  31. static float    PosLuzVerde [4] = {  0.0,  0.0,  1.0, 0.0 };
  32. static float    LuzAzul     [4] = {  0.0,  0.0,  1.0, 1.0 };
  33. static float    PosLuzAzul  [4] = { -1.0, -1.0, -1.0, 0.0 };
  34.  
  35. //
  36. // Funcion CALLBACK a llamar cuando de cambia el tama±o de la
  37. // ventana.
  38. //
  39. void CALLBACK CambioTamano(GLsizei Ancho, GLsizei Alto)
  40. {
  41.   glViewport(0, 0, Ancho, Alto);
  42.  
  43.   glMatrixMode(GL_PROJECTION);
  44.   glLoadIdentity();
  45.   gluPerspective(22.5, (float)Ancho / (float)Alto, 0.1, 1000.0);
  46.   glMatrixMode(GL_MODELVIEW);
  47. }
  48.  
  49. //
  50. // Funcion CALLBACK a llamar para dibujar cada fotograma.
  51. //
  52. void CALLBACK Dibuja(void)
  53. {
  54.   GLfloat CntAngulo;
  55.   GLfloat Radio;
  56.   int     iCnt;
  57.  
  58.   glEnable(GL_DEPTH_TEST);
  59.   glEnable(GL_LIGHTING);
  60.   glEnable(GL_LIGHT0);
  61.   glEnable(GL_LIGHT1);
  62.   glEnable(GL_LIGHT2);
  63.  
  64.   glShadeModel(GL_SMOOTH);
  65.  
  66.   glClearColor(0.0, 0.0, 0.0, 0.0);
  67.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  68.  
  69.   glLightfv(GL_LIGHT0, GL_DIFFUSE,  LuzRoja);
  70.   glLightfv(GL_LIGHT0, GL_POSITION, PosLuzRoja);
  71.  
  72.   glLightfv(GL_LIGHT1, GL_DIFFUSE,  LuzVerde);
  73.   glLightfv(GL_LIGHT1, GL_POSITION, PosLuzVerde);
  74.  
  75.   glLightfv(GL_LIGHT2, GL_DIFFUSE,  LuzAzul);
  76.   glLightfv(GL_LIGHT2, GL_POSITION, PosLuzAzul);
  77.  
  78.   Radio    = 3.0f;
  79.   for (iCnt=0;iCnt<3;iCnt++)
  80.   {
  81.     glPushMatrix();
  82.     glTranslatef(0.0, 0.0, -20.0);
  83.     switch (iCnt)
  84.     {
  85.       case 0:glRotatef   (Rotacion1,0.0, 0.0, 1.0);
  86.              break;
  87.       case 1:glRotatef   (Rotacion2,0.0, 1.0, 0.0);
  88.              break;
  89.       case 2:glRotatef   (Rotacion3,1.0, 0.0, 0.0);
  90.              break;
  91.     }
  92.     CntAngulo = 0.0f;
  93.     while (CntAngulo<6.28f)
  94.     {
  95.       glPushMatrix();
  96.       glTranslatef  (Radio*cos(CntAngulo),Radio*sin(CntAngulo),0.0);
  97.       switch (iCnt)
  98.       {
  99.         case 0: auxSolidSphere(1.0f);
  100.                 break;
  101.         case 1: auxSolidSphere(0.6f);
  102.                 break;
  103.         case 2: auxSolidSphere(0.5f);
  104.                 break;
  105.       }
  106.       glPopMatrix();
  107.       CntAngulo=CntAngulo+0.628f;
  108.     }
  109.     glPopMatrix();
  110.     Radio= Radio-0.8;
  111.   }
  112.   glPushMatrix();
  113.   glTranslatef(0.0, 0.0, -20.0);
  114.   auxSolidSphere (1.0f);
  115.   glPopMatrix();
  116.   auxSwapBuffers();
  117. }
  118.  
  119. //
  120. // Funcion callback Temporizador que actualiza las variables globales 
  121. // de rotacion de cada uno de los anillos.
  122. //
  123. void CALLBACK Temporizador(void)
  124. {
  125.   Rotacion1 += 2.0;
  126.   if (Rotacion1 >= 360.0) Rotacion1 -= 360.0;
  127.   Rotacion2 += 3.0;
  128.   if (Rotacion2 >= 360.0) Rotacion2 -= 360.0;
  129.   Rotacion3 += 1.0;
  130.   if (Rotacion3 >= 360.0) Rotacion3 -= 360.0;
  131.   Dibuja();
  132. }
  133.  
  134. //
  135. // Main - Hay algo mas sencillo? ;-)
  136. //
  137. void main(void)
  138. {
  139.   auxInitDisplayMode (AUX_RGB | AUX_DOUBLE | AUX_DEPTH);
  140.   auxInitPosition    (0,0,512,384);
  141.   auxInitWindow      ("Test CD ACTUAL");
  142.   auxReshapeFunc     (CambioTamano);
  143.   auxIdleFunc        (Temporizador);
  144.   auxMainLoop        (Dibuja);
  145. }
  146.  
  147.