L'exécutable

Image050.gif (6207 octets)

Le source: SchemaGLFrustum.cpp

/* Auteur: Nicolas JANEY                */
/* nicolas.janey@univ-fcomte.fr         */
/* Juin 2001                            */
/* Schema d'utilisation de la fonction  */
/* OpenGL glFrustum                     */

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

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

#include "ModuleCouleurs.h"
#include "ModuleReshape.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleFont.h"
#include "ModuleFleche.h"

typedef float vecteur[4];

static float g = -2.0F;
static float d = 2.0F;
static float b = -1.5F;
static float h = 1.5F;
static float cmin = 5.0F;
static float cmax = 10.0F;

void myinit(void) {
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_ALPHA_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glClearColor(1.0F,1.0F,0.9F,1.0F);
}

void axes() {
  setFont(GLUT_BITMAP_8_BY_13,CENTER);
  glColor4fv(couleurRouge());
  flecheEnVolume(1.0F,0.0F,0.0F,0.1F,0.3F,0.02F);
  glColor4fv(couleurVert());
  flecheEnVolume(0.0F,1.0F,0.0F,0.1F,0.3F,0.02F);
  glColor4fv(couleurBleu());
  flecheEnVolume(0.0F,0.0F,1.0F,0.1F,0.3F,0.02F);
  glPushAttrib(GL_DEPTH_TEST);
  glDisable(GL_DEPTH_TEST);
  glColor4fv(couleurRougeFonce());
  bitmapStringOutput(1.3F,0.0F,0.0F,"x");
  glColor4fv(couleurVertFonce());
  bitmapStringOutput(0.0F,1.3F,0.0F,"y");
  glColor4fv(couleurBleuFonce());
  bitmapStringOutput(0.0F,0.0F,1.3F,"z");
  glPopAttrib();
}

void display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  manipulateurSouris();
  manipulateurClavier();
  glEnable(GL_CULL_FACE);
  glColor4fv(couleurRose(0.2F));
  float fact = cmax/cmin;
  glBegin(GL_QUADS);
  glVertex3f(g*fact,h*fact,6.0F-cmax);
  glVertex3f(d*fact,h*fact,6.0F-cmax);
  glVertex3f(d*fact,b*fact,6.0F-cmax);
  glVertex3f(g*fact,b*fact,6.0F-cmax);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(g*fact,b*fact,6.0F-cmax);
  glVertex3f(g,b,6.0F-cmin);
  glVertex3f(g,h,6.0F-cmin);
  glVertex3f(g*fact,h*fact,6.0F-cmax);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(d*fact,h*fact,6.0F-cmax);
  glVertex3f(d,h,6.0F-cmin);
  glVertex3f(d,b,6.0F-cmin);
  glVertex3f(d*fact,b*fact,6.0F-cmax);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(g*fact,h*fact,6.0F-cmax);
  glVertex3f(g,h,6.0F-cmin);
  glVertex3f(d,h,6.0F-cmin);
  glVertex3f(d*fact,h*fact,6.0F-cmax);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(d*fact,b*fact,6.0F-cmax);
  glVertex3f(d,b,6.0F-cmin);
  glVertex3f(g,b,6.0F-cmin);
  glVertex3f(g*fact,b*fact,6.0F-cmax);
  glEnd();
  glDisable(GL_CULL_FACE);
  glClear(GL_DEPTH_BUFFER_BIT);
  glColor4fv(couleurBleuCiel(0.5F));
  glBegin(GL_QUADS);
  glVertex3f(g,b,6.0F-cmin);
  glVertex3f(d,b,6.0F-cmin);
  glVertex3f(d,h,6.0F-cmin);
  glVertex3f(g,h,6.0F-cmin);
  glEnd();
  glClear(GL_DEPTH_BUFFER_BIT);
  glColor4fv(couleurBleu());
  setFont(GLUT_BITMAP_8_BY_13,CENTER);
  bitmapStringOutput(0.0F,h/2,6.0F-cmin,"ecran");
  bitmapStringOutput(0.0F,-0.5F,4.0F,"axe de visee");
  glPushMatrix();
  glTranslatef(0.0F,0.0F,6.0F);
  flecheEnVolume(0.0F,0.0F,-4.0F,0.1F,0.3F,0.03F);
  glPopMatrix();
  glColor4fv(couleurRouge());
  placeFontCursor(d*(1+fact)/2,h/2,6.0F-(cmin+cmax)/2) ;
  bitmapStringOutput("volume de");
  deplacementCursor(0,13,0);
  bitmapStringOutput("visualisation");
  glColor4fv(couleurNoir());
  setFont(GLUT_BITMAP_9_BY_15,CENTER);
  bitmapStringOutput(g-0.5F,0.0F,6.0F-cmin,"g");
  bitmapStringOutput(d+0.5F,0.0F,6.0F-cmin,"d");
  bitmapStringOutput(0.0F,b-0.5F,6.0F-cmin,"b");
  bitmapStringOutput(0.0F,h+0.5F,6.0F-cmin,"h");
  bitmapStringOutput((d*fact)+2.0F,-0.3F,6.0F-cmin,"-cmin");
  bitmapStringOutput((d*fact)+2.0F,-0.3F,6.0F-cmax,"-cmax");
  glColor4fv(couleurRouge());
  glLineWidth(2.0);
  glBegin(GL_LINE_LOOP);
  glVertex3f(g,b,6.0F-cmin);
  glVertex3f(d,b,6.0F-cmin);
  glVertex3f(d,h,6.0F-cmin);
  glVertex3f(g,h,6.0F-cmin);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex3f(g*fact,b*fact,6.0F-cmax);
  glVertex3f(d*fact,b*fact,6.0F-cmax);
  glVertex3f(d*fact,h*fact,6.0F-cmax);
  glVertex3f(g*fact,h*fact,6.0F-cmax);
  glEnd();
  glBegin(GL_LINES);
  glVertex3f(g,b,6.0F-cmin);
  glVertex3f(g*fact,b*fact,6.0F-cmax);
  glVertex3f(d,b,6.0F-cmin);
  glVertex3f(d*fact,b*fact,6.0F-cmax);
  glVertex3f(d,h,6.0F-cmin);
  glVertex3f(d*fact,h*fact,6.0F-cmax);
  glVertex3f(g,h,6.0F-cmin);
  glVertex3f(g*fact,h*fact,6.0F-cmax);
  glEnd();
  glLineWidth(1.0);
  glEnable(GL_LINE_STIPPLE);
  glLineStipple(1,0x5555);
  glBegin(GL_LINES);
  glVertex3f(0.0F,0.0F,6.0F);
  glVertex3f(1000*d,1000*b,6.0F-1000*cmin);
  glVertex3f(0.0F,0.0F,6.0F);
  glVertex3f(1000*d,1000*h,6.0F-1000*cmin);
  glVertex3f(0.0F,0.0F,6.0F);
  glVertex3f(1000*g,1000*b,6.0F-1000*cmin);
  glVertex3f(0.0F,0.0F,6.0F);
  glVertex3f(1000*g,1000*h,6.0F-1000*cmin);
  glColor4fv(couleurBleu());
  glVertex3f(0.0F,0.0F,-10000.0F);
  glVertex3f(0.0F,0.0F,10000.0F);
  glColor4fv(couleurNoir());
  glVertex3f(0.0F,b,6.0F-cmin);
  glVertex3f(0.0F,h,6.0F-cmin);
  glVertex3f(g,0.0F,6.0F-cmin);
  glVertex3f((d*fact)+1.8F,0.0F,6.0F-cmin);
  glVertex3f((d*fact)+1.5F,-0.3F,6.0F-cmin);
  glVertex3f((d*fact)+1.5F,0.3F,6.0F-cmin);
  glVertex3f(0.0F,0.0F,6.0F-cmax);
  glVertex3f((d*fact)+1.8F,0.0F,6.0F-cmax);
  glVertex3f((d*fact)+1.5F,-0.3F,6.0F-cmax);
  glVertex3f((d*fact)+1.5F,0.3F,6.0F-cmax);
  glVertex3f((d*fact)+1.5F,0.0F,-10000.0F);
  glVertex3f((d*fact)+1.5F,0.0F,10000.0F);
  glVertex3f(1.0F,0.0F,6.0F);
  glVertex3f((d*fact)+2.8F,0.0F,6.0F);
  glEnd();
  glDisable(GL_LINE_STIPPLE);
  glPushMatrix();
  glTranslatef(0.0F,0.0F,6.0F);
  axes();
  glPopMatrix();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 'g'  : g += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'G'  : g -= 0.1F;
                  glutPostRedisplay();
                  break;
      case 'd'  : d += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'D'  : d -= 0.1F;
                  glutPostRedisplay();
                  break;
      case 'b'  : b += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'B'  : b -= 0.1F;
                  glutPostRedisplay();
                  break;
      case 'h'  : h += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'H'  : h -= 0.1F;
                  glutPostRedisplay();
                  break;
      case 'i'  : cmin += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'I'  : cmin -= 0.1F;
                  glutPostRedisplay();
                  break;
      case 'a'  : cmax += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'A'  : cmax -= 0.1F;
                  glutPostRedisplay();
                  break; }
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
  glutInitWindowPosition(10,10);
  glutInitWindowSize(400,250);
  glutCreateWindow("Schema: Fonction OpenGL glFrustum");
  myinit();
  creationMenuBasique();
  setParametresOrthoBasique(-4.5,4.5,-4.5,4.5,-500.0,500.0);
  setManipulateurDistance(1.0F);
  setManipulateurClavierAngle(10.0F,-68.0F,0.0F) ;
  glutReshapeFunc(reshapeOrthoBasique);
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutDisplayFunc(display);
  glutMainLoop();
  return(0);
}

/* ************************************************** */

Les modules utilitaires : Modules.zip

WB01624_.gif (281 octets) RETOUR