/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Modelisation OpenGL d'une scene */ /* composee de colonnes pour l'obtention */ /* d'un temple */ #include "windows.h" #include #include #include #include #include #include "ModuleFont.h" static GLfloat view_rotx=35.0F ; static GLfloat view_roty=20.0F ; static GLfloat view_rotz=0.0F ; static int colonnes = 8 ; static int type = 0 ; static int maille = 0 ; static float noir[] = { 1.0F,1.0F,1.0F,0.5F }; static float rouge[] = { 1.0F,0.0F,0.0F,1.0F }; static float vert[] = { 0.0F,1.0F,0.0F,1.0F }; static float bleu[] = { 0.0F,0.0F,1.0F,1.0F }; static float jaune[] = { 1.0F,1.0F,0.0F,1.0F }; static float magenta[] = { 1.0F,0.0F,1.0F,1.0F }; static float cyan[] = { 0.0F,1.0F,1.0F,1.0F }; static float blanc[] = { 1.0F,1.0F,1.0F,0.5F }; void myinit(void) { GLfloat light_ambient[] = { 0.0F,0.0F,0.0F,1.0F }; GLfloat light_diffuse[] = { 1.0F,1.0F,1.0F,1.0F }; GLfloat light_specular[] = { 0.0F,0.0F,0.0F,1.0F }; GLfloat light_position0[] = { 0.0F,0.0F,1.0F,0.0F }; GLfloat light_position1[] = { 0.0F,0.0F,1.0F,0.0F }; glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT1,GL_DIFFUSE,light_diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); glLightfv(GL_LIGHT0,GL_POSITION,light_position0); glLightfv(GL_LIGHT1,GL_POSITION,light_position1); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_AUTO_NORMAL); glDepthFunc(GL_LESS); glClearAccum(0.0,0.0,0.0,0.0); makeRasterFont(); } void axes() { glPushMatrix() ; glColor4fv(rouge) ; glBegin(GL_LINES) ; glVertex3f(0.0F,0.0F,0.0F) ; glVertex3f(1.0F,0.0F,0.0F) ; glEnd() ; glRasterPos3f(1.05F,0.05F,0.05F); printString("x"); glColor4fv(vert) ; glBegin(GL_LINES) ; glVertex3f(0.0F,0.0F,0.0F) ; glVertex3f(0.0F,1.0F,0.0F) ; glEnd() ; glRasterPos3f(0.05F,1.05F,0.05F); printString("y"); glColor4fv(bleu) ; glBegin(GL_LINES) ; glVertex3f(0.0F,0.0F,0.0F) ; glVertex3f(0.0F,0.0F,1.0F) ; glEnd() ; glRasterPos3f(0.05F,0.05F,1.05F); printString("z"); if ( maille ) { float gris[] = { 0.5F,0.5F,0.5F,1.0F }; glColor4fv(gris) ; for ( int i = -100 ; i < 100 ; i++ ) { glBegin(GL_LINES) ; glVertex3f((float) i,0.0F,200.0F) ; glVertex3f((float) i,0.0F,-200.0F) ; glEnd() ; glBegin(GL_LINES) ; glVertex3f(200.0F,0.0F,(float) i) ; glVertex3f(-200.0F,0.0F,(float) i) ; glEnd() ; } } glPopMatrix() ; } void cotesColonne(void) { glPushMatrix(); glColor3fv(rouge) ; auxWireBox(2.0,0.6,2.0) ; glTranslatef(0.0F,1.8F,0.0F) ; glColor3fv(vert) ; auxWireBox(1.2,3.0,1.2) ; glTranslatef(0.0F,1.7F,0.0F) ; glColor3fv(bleu) ; auxWireBox(2.0,0.4,2.0) ; glPopMatrix(); } void colonne(void) { glPushMatrix(); glMaterialfv(GL_FRONT,GL_DIFFUSE,rouge) ; auxSolidBox(2.0,0.6,2.0) ; glTranslatef(0.0F,1.8F,0.0F) ; glMaterialfv(GL_FRONT,GL_DIFFUSE,vert) ; auxSolidBox(1.2,3.0,1.2) ; glTranslatef(0.0F,1.7F,0.0F) ; glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu) ; auxSolidBox(2.0,0.4,2.0) ; glPopMatrix(); } void cotesColonneFrise(float d, float a) { glPushMatrix(); glColor3fv(rouge) ; auxWireBox(2.0,0.6,2.0) ; glTranslatef(0.0F,1.8F,0.0F) ; glColor3fv(vert) ; auxWireBox(1.2,3.0,1.2) ; glTranslatef(0.0F,1.7F,0.0F) ; glColor3fv(bleu) ; auxWireBox(2.0,0.4,2.0) ; glRotatef(a,0.0f,1.0f,0.0f); glTranslatef(0.0f,0.4f,-d/2.0f); glColor3fv(blanc) ; auxWireBox(2.0,0.4,d) ; glPopMatrix(); } void colonneFrise(float d, float a) { glPushMatrix(); glMaterialfv(GL_FRONT,GL_DIFFUSE,rouge) ; auxSolidBox(2.0,0.6,2.0) ; glTranslatef(0.0F,1.8F,0.0F) ; glMaterialfv(GL_FRONT,GL_DIFFUSE,vert) ; auxSolidBox(1.2,3.0,1.2) ; glTranslatef(0.0F,1.7F,0.0F) ; glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu) ; auxSolidBox(2.0,0.4,2.0) ; glRotatef(a,0.0f,1.0f,0.0f); glTranslatef(0.0f,0.4f,-d/2.0f); glMaterialfv(GL_FRONT,GL_DIFFUSE,blanc) ; auxSolidBox(2.0,0.4,d) ; glPopMatrix(); } void displayCotesColonne(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); glEnable(GL_DEPTH_TEST); cotesColonne(); axes() ; glDisable(GL_DEPTH_TEST); glPopMatrix(); glAccum(GL_ACCUM,0.7F); } void displayColonne(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); colonne(); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glPopMatrix(); glAccum(GL_ACCUM,0.3F); } void displayTemple(int n) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); for ( int i = 0 ; i < n ; i++ ) { glPushMatrix(); glRotatef((float) ((i*360)/n),0.0f,1.0f,0.0f); glTranslatef(6.0f,0.0f,0.0f); colonne(); glPopMatrix(); } glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glPopMatrix(); glAccum(GL_ACCUM,0.3F); } void displayCotesTemple(int n) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); glEnable(GL_DEPTH_TEST); for ( int i = 0 ; i < n ; i++ ) { glPushMatrix(); glRotatef((float) ((i*360)/n),0.0f,1.0f,0.0f); glTranslatef(6.0f,0.0f,0.0f); cotesColonne(); glPopMatrix(); } axes() ; glDisable(GL_DEPTH_TEST); glPopMatrix(); glAccum(GL_ACCUM,0.7F); } void displayTempleFrise(int n) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); float d = 12 * 3.14159F / n ; float a =(float) 180 / n ; for ( int i = 0 ; i < n ; i++ ) { glPushMatrix(); glRotatef((float) ((i*360)/n),0.0f,1.0f,0.0f); glTranslatef(6.0f,0.0f,0.0f); colonneFrise(d,a); glPopMatrix(); } glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glPopMatrix(); glAccum(GL_ACCUM,0.3F); } void displayCotesTempleFrise(int n) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); glEnable(GL_DEPTH_TEST); float d = 12 * 3.14159F / n ; float a =(float) 180 / n ; for ( int i = 0 ; i < n ; i++ ) { glPushMatrix(); glRotatef((float) ((i*360)/n),0.0f,1.0f,0.0f); glTranslatef(6.0f,0.0f,0.0f); cotesColonneFrise(d,a); glPopMatrix(); } axes() ; glDisable(GL_DEPTH_TEST); glPopMatrix(); glAccum(GL_ACCUM,0.7F); } void CALLBACK display(void) { glClear(GL_ACCUM_BUFFER_BIT); glPushMatrix() ; if ( type == 0 ) { displayColonne() ; displayCotesColonne() ; } if ( type == 1 ) { glScalef(0.6f,0.6f,0.6f); displayTemple(colonnes) ; displayCotesTemple(colonnes) ; } if ( type == 2 ) { glScalef(0.6f,0.6f,0.6f); displayTempleFrise(colonnes) ; displayCotesTempleFrise(colonnes) ; } glAccum(GL_RETURN,1.0); glPopMatrix() ; glFlush(); auxSwapBuffers() ; } void CALLBACK myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-5.0,5.0,-h*5.0/w,h*5.0/w,-100.0,100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void CALLBACK keyx(void) { view_rotx += 4 ; } void CALLBACK keyX(void) { view_rotx -= 4 ; } void CALLBACK keyy(void) { view_roty += 4 ; } void CALLBACK keyY(void) { view_roty -= 4 ; } void CALLBACK keyz(void) { view_rotz += 4 ; } void CALLBACK keyZ(void) { view_rotz -= 4 ; } void CALLBACK keyReturn(void) { type = (type+1)%3 ; } void CALLBACK keySpace(void) { maille = 1 - maille ; } void CALLBACK keyUp(void) { colonnes++ ; } void CALLBACK keyDown(void) { colonnes-- ; if ( colonnes < 2 ) colonnes = 2 ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH|AUX_ACCUM); auxInitPosition(0,0,200,200); auxInitWindow("Temple"); myinit(); auxKeyFunc(AUX_x,keyx) ; auxKeyFunc(AUX_X,keyX) ; auxKeyFunc(AUX_y,keyy) ; auxKeyFunc(AUX_Y,keyY) ; auxKeyFunc(AUX_z,keyz) ; auxKeyFunc(AUX_Z,keyZ) ; auxKeyFunc(AUX_RETURN,keyReturn) ; auxKeyFunc(AUX_SPACE,keySpace) ; auxKeyFunc(AUX_UP,keyUp) ; auxKeyFunc(AUX_DOWN,keyDown) ; auxReshapeFunc(myReshape); auxMainLoop(display); }