/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Janvier 2003 */
/* Star Wars Introduction */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
static float z = 100.0F ;
static float dz = -0.1F ;
static int nl = 19 ;
void myinit(void) {
GLfloat jaune[] = { 1.0F,1.0F,0.0F,0.0F };
GLfloat noir[] = { 0.0F,0.0F,0.0F,0.0F };
glEnable(GL_FOG);
glFogi(GL_FOG_MODE,GL_LINEAR);
glHint(GL_FOG_HINT,GL_NICEST);
glFogf(GL_FOG_START,3.0F);
glFogf(GL_FOG_END,50.0F);
glFogfv(GL_FOG_COLOR,noir);
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glColor4fv(jaune);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
}
void stroke_output(GLfloat x,GLfloat y,char *format,...) {
va_list args;
char buffer[500],*p;
va_start(args,format);
vsprintf(buffer,format,args);
va_end(args);
float fact = 0.01F;
float largeur = fact*glutStrokeLength(GLUT_STROKE_ROMAN,(unsigned char *) buffer);
glPushMatrix();
glTranslatef(x-largeur/2,y,0);
glScalef(fact,fact,fact);
for ( p = buffer ; *p ; p++ )
glutStrokeCharacter(GLUT_STROKE_ROMAN,*p);
glPopMatrix();
}
static char *texte[] = { "C'EST UNE EPOQUE DE GUERRE CIVILE.",
"A BORD DE VAISSEAUX SPATIAUX",
"OPERANT A PARTIR D'UNE BASE INCONNUE,",
"LES REBELLES ONT REMPORTE LEUR PREMIERE",
"VICTOIRE SUR L'ABOMINABLE EMPIRE GALACTIQUE",
"",
"AU COURS DE LA BATAILLE LES REBELLES",
"ONT REUSSI A DEROBER LES PLANS SECRETS",
"DE L'ARME ABSOLUE DE L'EMPIRE :",
"L'ETOILE NOIRE, UNE STATION SPATIALE",
"DOTEE D'UN ARMEMENT ASSEZ PUISSANT",
"POUR ANNIHILER UNE PLANETE TOUTE ENTIERE",
"",
"POURSUIVIS PAR LES SBIRES SINISTRES",
"DE L'EMPIRE, LA PRINCESSE LEIA REGAGNE",
"SA BASE DANS SON VAISSEAU COSMIQUE",
"PORTEUSE DES PLANS VOLES A L'ENNEMI",
"QUI POURRONT SAUVER SON PEUPLE",
"ET RESTAURER LA LIBERTEE DANS LA GALAXIE..." };
void scene(void) {
glPushMatrix();
glTranslatef(0.0F,-8.0F,z+50.0F) ;
for ( int z = 0 ; z < nl ; z++ ) {
glPushMatrix();
glTranslatef(0.0F,1.5F,-5.0F*z) ;
glRotatef(-80.0F,1.0F,0.0F,0.0F);
stroke_output(0.0F,0.0F,texte[nl-1-z]);
glPopMatrix(); }
glPopMatrix();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
scene();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void idle(void) {
z += dz ;
if ( z <= -60 )
z = 100 ;
glutPostRedisplay() ;
}
void reshape(int w,int h) {
float xmin,xmax,ymin,ymax;
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if( w <= h) {
xmin = -2.5F;
xmax = 2.5F;
ymin = -2.5F*(double) h/w;
ymax = 2.5F*(double) h/w; }
else {
xmin = -2.5F*(double) w/h;
xmax = 2.5F*(double) w/h;
ymax = 2.5F;
ymin = -2.5F; }
glFrustum(xmin,xmax,ymin,ymax,3.0F,1000.0F);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,30.0,0.0,-10.0,0.0,0.0,1.0,0.0);
}
void key(unsigned char k,int x,int y) {
static int anim = 1;
switch (k) {
case ' ' : anim = !anim;
glutIdleFunc((anim) ? idle : NULL);
break;
case 0x1B : exit(0); }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(450,250);
glutInitWindowPosition(50,50);
glutCreateWindow("Star Wars Intro");
myinit();
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}