L'exécutable

  Image0001.gif (4200 octets)  Image0001.gif (4200 octets)

  Image0001.gif (4200 octets)  Image0001.gif (4200 octets)

Le source : TD-Minilangage-Cubes.cpp

#include "windows.h"

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

#include <stdio.h>
#include <math.h>

#include "ModuleFont.h"

static GLfloat view_rotx=35.0F ;
static GLfloat view_roty=20.0F ;
static GLfloat view_rotz=0.0F ;
static float ymax ;
static int type = 0 ;
static int maille = 0 ;

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() ;
  float rouge[] = { 1.0F,1.0F,0.0F,1.0F };
  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");
  float vert[] = { 0.0F,1.0F,1.0F,1.0F };
  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");
  float bleu[] = { 1.0F,0.0F,1.0F,1.0F };
  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 displayCotes(void) {
  float jaune[] = { 1.0F,1.0F,0.0F,1.0F };
  float blanc[] = { 1.0F,1.0F,1.0F,0.5F };
  float rouge[] = { 1.0F,0.0F,0.0F,0.5F };
  float vert[] = { 0.0F,1.0F,0.0F,0.5F };
  float bleu[] = { 0.0F,0.0F,1.0F,0.5F };
  float magenta[] = { 1.0F,0.0F,1.0F,1.0F };
  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);
  glPushMatrix();
  glTranslatef(1.5F,0.0F,-1.5F) ;
  glColor3fv(rouge) ;
  auxWireCube(1.0) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-1.5F,0.0F,-1.5F) ;
  glColor3fv(vert) ;
  if ( type > 3 ) {
    glRotatef(30.0F,0.0F,1.0F,0.0F) ;
    glTranslatef(0.0F,0.0F,-0.5F) ; }
    else
    if ( type > 2 ) {
      glRotatef(40.0F,0.0F,1.0F,0.0F) ;
      glScalef(1.0F,1.0F,2.0F) ; }
  auxWireCube(1.0) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-1.5F,0.0F,1.5F) ;
  glColor3fv(blanc) ;
  if ( type > 1 )
    glScalef(1.0F,1.0F,2.0F) ;
  auxWireCube(1.0) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(1.5F,0.0F,1.5F) ;
  glColor3fv(bleu) ;
  if ( type > 0 )
    glRotatef(45.0F,0.0F,1.0F,0.0F) ;
  auxWireCube(1.0) ;
  glPopMatrix();
  axes() ;
  glDisable(GL_DEPTH_TEST);
  glPopMatrix();
  glAccum(GL_ACCUM,0.7F);
}

void displayCubes(void) {
  float blanc[] = { 1.0F,1.0F,1.0F,0.5F };
  float rouge[] = { 1.0F,0.0F,0.0F,0.5F };
  float vert[] = { 0.0F,1.0F,0.0F,0.5F };
  float bleu[] = { 0.0F,0.0F,1.0F,0.5F };
  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);
  glPushMatrix();
  glTranslatef(1.5F,0.0F,-1.5F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,rouge) ;
  auxSolidCube(1.0) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-1.5F,0.0F,-1.5F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,vert) ;
  if ( type > 3 ) {
    glRotatef(30.0F,0.0F,1.0F,0.0F) ;
    glTranslatef(0.0F,0.0F,-0.5F) ; }
    else
    if ( type > 2 ) {
      glRotatef(40.0F,0.0F,1.0F,0.0F) ;
      glScalef(1.0F,1.0F,2.0F) ; }
  auxSolidCube(1.0) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-1.5F,0.0F,1.5F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,blanc) ;
  if ( type > 1 )
    glScalef(1.0F,1.0F,2.0F) ;
  auxSolidCube(1.0) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(1.5F,0.0F,1.5F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu) ;
  if ( type > 0 )
    glRotatef(45.0F,0.0F,1.0F,0.0F) ;
  auxSolidCube(1.0) ;
  glPopMatrix();
  glDisable(GL_LIGHTING);
  glPopMatrix();
  glAccum(GL_ACCUM,0.3F);
}

void CALLBACK display(void) {
  glClear(GL_ACCUM_BUFFER_BIT);
  glPushMatrix() ;
  displayCubes() ;
  displayCotes() ;
  glAccum(GL_RETURN,1.0);
  glPopMatrix() ;
  glFlush();
  auxSwapBuffers() ;
}
void CALLBACK myReshape(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  ymax = h*3.0F/w ;
  glOrtho(-3.0,3.0,-h*3.0/w,h*3.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)%5 ;
}

void CALLBACK keySpace(void) {
  maille = 1 - maille ;
}

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH|AUX_ACCUM);
  auxInitPosition(0,0,200,200);
  auxInitWindow("Mini-langage");
  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) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}

Le source : ModuleFont.cpp

Le source : ModuleFont.h

WB01624_.gif (281 octets) RETOUR