home *** CD-ROM | disk | FTP | other *** search
- // ============================================================
- // LeaRNWaRe code by CROM / Spanish Lords
- // - since 1993 -
- //
- // Objetivo : Ejemplo de manejo de la libreria aux de OpenGL
- // Autor : Pedro Ant≤n Alonso. crom@ergos.es
- // Plataforma : Windows 95/98/NT/2000
- // Compilador : Visual C++ 6.0
- //
- // ============================================================
- #include <windows.h>
- #include <math.h> // Para calcular los senos y cosenos
- #include <gl\gl.h> // Libreria OpenGL
- #include <gl\glaux.h> // Libreria AUX de OpenGL
-
- //
- // Variables globales.
- // -------------------
- //
- // Rotacion de cada uno de los anillos de la escena.
- //
- GLfloat Rotacion1 = 0.0;
- GLfloat Rotacion2 = 0.0;
- GLfloat Rotacion3 = 0.0;
- //
- // Definici≤n de las tres luces que intervienen en la escena
- //
- static float LuzRoja [4] = { 1.0, 0.0, 0.0, 1.0 };
- static float PosLuzRoja [4] = { 1.0, 1.0, 1.0, 0.0 };
- static float LuzVerde [4] = { 0.0, 0.3, 0.0, 1.0 };
- static float PosLuzVerde [4] = { 0.0, 0.0, 1.0, 0.0 };
- static float LuzAzul [4] = { 0.0, 0.0, 1.0, 1.0 };
- static float PosLuzAzul [4] = { -1.0, -1.0, -1.0, 0.0 };
-
- //
- // Funcion CALLBACK a llamar cuando de cambia el tama±o de la
- // ventana.
- //
- void CALLBACK CambioTamano(GLsizei Ancho, GLsizei Alto)
- {
- glViewport(0, 0, Ancho, Alto);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(22.5, (float)Ancho / (float)Alto, 0.1, 1000.0);
- glMatrixMode(GL_MODELVIEW);
- }
-
- //
- // Funcion CALLBACK a llamar para dibujar cada fotograma.
- //
- void CALLBACK Dibuja(void)
- {
- GLfloat CntAngulo;
- GLfloat Radio;
- int iCnt;
-
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHT1);
- glEnable(GL_LIGHT2);
-
- glShadeModel(GL_SMOOTH);
-
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- glLightfv(GL_LIGHT0, GL_DIFFUSE, LuzRoja);
- glLightfv(GL_LIGHT0, GL_POSITION, PosLuzRoja);
-
- glLightfv(GL_LIGHT1, GL_DIFFUSE, LuzVerde);
- glLightfv(GL_LIGHT1, GL_POSITION, PosLuzVerde);
-
- glLightfv(GL_LIGHT2, GL_DIFFUSE, LuzAzul);
- glLightfv(GL_LIGHT2, GL_POSITION, PosLuzAzul);
-
- Radio = 3.0f;
- for (iCnt=0;iCnt<3;iCnt++)
- {
- glPushMatrix();
- glTranslatef(0.0, 0.0, -20.0);
- switch (iCnt)
- {
- case 0:glRotatef (Rotacion1,0.0, 0.0, 1.0);
- break;
- case 1:glRotatef (Rotacion2,0.0, 1.0, 0.0);
- break;
- case 2:glRotatef (Rotacion3,1.0, 0.0, 0.0);
- break;
- }
- CntAngulo = 0.0f;
- while (CntAngulo<6.28f)
- {
- glPushMatrix();
- glTranslatef (Radio*cos(CntAngulo),Radio*sin(CntAngulo),0.0);
- switch (iCnt)
- {
- case 0: auxSolidSphere(1.0f);
- break;
- case 1: auxSolidSphere(0.6f);
- break;
- case 2: auxSolidSphere(0.5f);
- break;
- }
- glPopMatrix();
- CntAngulo=CntAngulo+0.628f;
- }
- glPopMatrix();
- Radio= Radio-0.8;
- }
- glPushMatrix();
- glTranslatef(0.0, 0.0, -20.0);
- auxSolidSphere (1.0f);
- glPopMatrix();
- auxSwapBuffers();
- }
-
- //
- // Funcion callback Temporizador que actualiza las variables globales
- // de rotacion de cada uno de los anillos.
- //
- void CALLBACK Temporizador(void)
- {
- Rotacion1 += 2.0;
- if (Rotacion1 >= 360.0) Rotacion1 -= 360.0;
- Rotacion2 += 3.0;
- if (Rotacion2 >= 360.0) Rotacion2 -= 360.0;
- Rotacion3 += 1.0;
- if (Rotacion3 >= 360.0) Rotacion3 -= 360.0;
- Dibuja();
- }
-
- //
- // Main - Hay algo mas sencillo? ;-)
- //
- void main(void)
- {
- auxInitDisplayMode (AUX_RGB | AUX_DOUBLE | AUX_DEPTH);
- auxInitPosition (0,0,512,384);
- auxInitWindow ("Test CD ACTUAL");
- auxReshapeFunc (CambioTamano);
- auxIdleFunc (Temporizador);
- auxMainLoop (Dibuja);
- }
-
-