/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Modelisation OpenGL d'une scene */
/* composee de colonnes pour l'obtention */
/* d'un temple */
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include <math.h>
#include "ModuleCouleurs.h"
#include "ModuleFont.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
static int colonnes = 8 ;
static int type = 0 ;
static int maille = 0 ;
void myinit(void) {
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,couleurNoir());
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurNoir());
glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LESS);
glClearAccum(0.0,0.0,0.0,0.0);
}
void axes() {
glPushMatrix() ;
glColor4fv(couleurRouge()) ;
glBegin(GL_LINES) ;
glVertex3f(0.0F,0.0F,0.0F) ;
glVertex3f(1.0F,0.0F,0.0F) ;
glEnd() ;
placeFontCursor(1.05F,0.05F,0.05F);
simpleBitmapOutput("x");
glColor4fv(couleurVert()) ;
glBegin(GL_LINES) ;
glVertex3f(0.0F,0.0F,0.0F) ;
glVertex3f(0.0F,1.0F,0.0F) ;
glEnd() ;
placeFontCursor(0.05F,1.05F,0.05F);
simpleBitmapOutput("y");
glColor4fv(couleurBleu()) ;
glBegin(GL_LINES) ;
glVertex3f(0.0F,0.0F,0.0F) ;
glVertex3f(0.0F,0.0F,1.0F) ;
glEnd() ;
placeFontCursor(0.05F,0.05F,1.05F);
simpleBitmapOutput("z");
if ( maille ) {
glColor4fv(couleurGrisMoyen()) ;
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();
glColor4fv(couleurRouge()) ;
glPushMatrix();
glScalef(2.0F,0.6F,2.0F) ;
glutWireCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.8F,0.0F) ;
glColor4fv(couleurVert()) ;
glPushMatrix();
glScalef(1.2F,3.0F,1.2F) ;
glutWireCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.7F,0.0F) ;
glColor4fv(couleurBleu()) ;
glPushMatrix();
glScalef(2.0F,0.4F,2.0F) ;
glutWireCube(1.0) ;
glPopMatrix();
glPopMatrix();
}
void colonne(void) {
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge()) ;
glPushMatrix();
glScalef(2.0F,0.6F,2.0F) ;
glutSolidCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.8F,0.0F) ;
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert()) ;
glPushMatrix();
glScalef(1.2F,3.0F,1.2F) ;
glutSolidCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.7F,0.0F) ;
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu()) ;
glPushMatrix();
glScalef(2.0F,0.4F,2.0F) ;
glutSolidCube(1.0) ;
glPopMatrix();
glPopMatrix();
}
void cotesColonneFrise(float d, float a) {
glPushMatrix();
glColor4fv(couleurRouge()) ;
glPushMatrix();
glScalef(2.0F,0.6F,2.0F) ;
glutWireCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.8F,0.0F) ;
glColor4fv(couleurVert()) ;
glPushMatrix();
glScalef(1.2F,3.0F,1.2F) ;
glutWireCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.7F,0.0F) ;
glColor4fv(couleurBleu()) ;
glPushMatrix();
glScalef(2.0F,0.4F,2.0F) ;
glutWireCube(1.0) ;
glPopMatrix();
glRotatef(a,0.0f,1.0f,0.0f);
glTranslatef(0.0f,0.4f,-d/2.0f);
glColor4fv(couleurBlanc()) ;
glPushMatrix();
glScalef(2.0F,0.4F,d) ;
glutWireCube(1.0) ;
glPopMatrix();
glPopMatrix();
}
void colonneFrise(float d, float a) {
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge()) ;
glPushMatrix();
glScalef(2.0F,0.6F,2.0F) ;
glutSolidCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.8F,0.0F) ;
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert()) ;
glPushMatrix();
glScalef(1.2F,3.0F,1.2F) ;
glutSolidCube(1.0) ;
glPopMatrix();
glTranslatef(0.0F,1.7F,0.0F) ;
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu()) ;
glPushMatrix();
glScalef(2.0F,0.4F,2.0F) ;
glutSolidCube(1.0) ;
glPopMatrix();
glRotatef(a,0.0f,1.0f,0.0f);
glTranslatef(0.0f,0.4f,-d/2.0f);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBlanc()) ;
glPushMatrix();
glScalef(2.0F,0.4F,d) ;
glutSolidCube(1.0) ;
glPopMatrix();
glPopMatrix();
}
void displayCotesColonne(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
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();
manipulateurSouris();
manipulateurClavier();
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();
manipulateurSouris();
manipulateurClavier();
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();
manipulateurSouris();
manipulateurClavier();
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();
manipulateurSouris();
manipulateurClavier();
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();
manipulateurSouris();
manipulateurClavier();
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 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();
glutSwapBuffers() ;
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 43 : colonnes++ ;
glutPostRedisplay();
break ;
case 45 : colonnes-- ;
if ( colonnes < 2 )
colonnes = 2 ;
glutPostRedisplay();
break ;
case 32 : maille = 1 - maille ;
glutPostRedisplay();
break ;
case 0x0D : type = (type+1)%3 ;
glutPostRedisplay();
break ; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_ACCUM);
glutInitWindowSize(200,200);
glutInitWindowPosition(50,50);
glutCreateWindow("Temple");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-5.0,5.0,-5.0,5.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}