L'exécutable

Image050.gif (6207 octets)

Le source: SchemaGLOrtho.cpp

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

#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 tx = 2.8F;
static float ty = 2.1F;
static float tz = 3.2F;

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));
  glBegin(GL_QUADS);
  glVertex3f(tx,ty,-tz);
  glVertex3f(tx,-ty,-tz);
  glVertex3f(-tx,-ty,-tz);
  glVertex3f(-tx,ty,-tz);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(tx,ty,tz);
  glVertex3f(tx,-ty,tz);
  glVertex3f(tx,-ty,-tz);
  glVertex3f(tx,ty,-tz);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(-tx,ty,-tz);
  glVertex3f(-tx,-ty,-tz);
  glVertex3f(-tx,-ty,tz);
  glVertex3f(-tx,ty,tz);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(tx,ty,-tz);
  glVertex3f(-tx,ty,-tz);
  glVertex3f(-tx,ty,tz);
  glVertex3f(tx,ty,tz);
  glEnd();
  glBegin(GL_QUADS);
  glVertex3f(tx,-ty,tz);
  glVertex3f(-tx,-ty,tz);
  glVertex3f(-tx,-ty,-tz);
  glVertex3f(tx,-ty,-tz);
  glEnd();
  glDisable(GL_CULL_FACE);
  glClear(GL_DEPTH_BUFFER_BIT);
  glColor4fv(couleurBleuCiel(0.5F));
  glBegin(GL_QUADS);
  glVertex3f(-tx,ty,tz);
  glVertex3f(-tx,-ty,tz);
  glVertex3f(tx,-ty,tz);
  glVertex3f(tx,ty,tz);
  glEnd();
  glClear(GL_DEPTH_BUFFER_BIT);
  glColor4fv(couleurBleu());
  setFont(GLUT_BITMAP_8_BY_13,CENTER);
  bitmapStringOutput(0.0F,1.0F,tz,"ecran");
  bitmapStringOutput(0.0F,0.0F,5.0F,"axe de visee");
  glPushMatrix();
  glTranslatef(0.0F,0.0F,6.0F);
  flecheEnVolume(0.0F,0.0F,-3.5F,0.1F,0.3F,0.03F);
  glPopMatrix();
  glColor4fv(couleurRouge());
  placeFontCursor(tx,0.0F,0.0F) ;
  bitmapStringOutput("volume de");
  deplacementCursor(0,13,0);
  bitmapStringOutput("visualisation");
  glColor4fv(couleurNoir());
  setFont(GLUT_BITMAP_9_BY_15,CENTER);
  bitmapStringOutput(-tx-0.5F,0.0F,tz,"g");
  bitmapStringOutput(tx+0.5F,0.0F,tz,"d");
  bitmapStringOutput(0.0F,-ty-0.5F,tz,"b");
  bitmapStringOutput(0.0F,ty+0.5F,tz,"h");
  bitmapStringOutput(tx+2.0F,-ty-0.3F,tz,"-cmin");
  bitmapStringOutput(tx+2.0F,-ty-0.3F,-tz,"-cmax");
  glColor4fv(couleurRouge());
  glLineWidth(2.0);
  glBegin(GL_LINE_LOOP);
  glVertex3f(tx,ty,-tz);
  glVertex3f(tx,-ty,-tz);
  glVertex3f(-tx,-ty,-tz);
  glVertex3f(-tx,ty,-tz);
  glEnd();
  glBegin(GL_LINE_LOOP);
  glVertex3f(tx,ty,tz);
  glVertex3f(tx,-ty,tz);
  glVertex3f(-tx,-ty,tz);
  glVertex3f(-tx,ty,tz);
  glEnd();
  glBegin(GL_LINES);
  glVertex3f(tx,ty,-tz);
  glVertex3f(tx,ty,tz);
  glVertex3f(tx,-ty,-tz);
  glVertex3f(tx,-ty,tz);
  glVertex3f(-tx,-ty,-tz);
  glVertex3f(-tx,-ty,tz);
  glVertex3f(-tx,ty,-tz);
  glVertex3f(-tx,ty,tz);
  glEnd();
  glLineWidth(1.0);
  glEnable(GL_LINE_STIPPLE);
  glLineStipple(1,0x5555);
  glBegin(GL_LINES);
  glVertex3f(tx,ty,-tz);
  glVertex3f(tx,ty,-tz-10000.0F);
  glVertex3f(tx,-ty,-tz);
  glVertex3f(tx,-ty,-tz-10000.0F);
  glVertex3f(-tx,-ty,-tz);
  glVertex3f(-tx,-ty,-tz-10000.0F);
  glVertex3f(-tx,ty,-tz);
  glVertex3f(-tx,ty,-tz-10000.0F);
  glVertex3f(tx,ty,tz);
  glVertex3f(tx,ty,tz+10000.0F);
  glVertex3f(tx,-ty,tz);
  glVertex3f(tx,-ty,tz+10000.0F);
  glVertex3f(-tx,-ty,tz);
  glVertex3f(-tx,-ty,tz+10000.0F);
  glVertex3f(-tx,ty,tz);
  glVertex3f(-tx,ty,tz+10000.0F);
  glColor4fv(couleurBleu());
  glVertex3f(0.0F,0.0F,-10000.0F);
  glVertex3f(0.0F,0.0F,10000.0F);
  glColor4fv(couleurNoir());
  glVertex3f(tx+1.2F,-ty,tz);
  glVertex3f(tx+1.8F,-ty,tz);
  glVertex3f(tx+1.5F,-ty-0.3F,tz);
  glVertex3f(tx+1.5F,-ty+0.3F,tz);
  glVertex3f(tx+1.2F,-ty,-tz);
  glVertex3f(tx+1.8F,-ty,-tz);
  glVertex3f(tx+1.5F,-ty-0.3F,-tz);
  glVertex3f(tx+1.5F,-ty+0.3F,-tz);
  glVertex3f(tx+1.5F,-ty,-10000.0F);
  glVertex3f(tx+1.5F,-ty,10000.0F);
  glEnd();
  glDisable(GL_LINE_STIPPLE);
  glPushMatrix();
  glTranslatef(1.0F,1.0F,-1.0F);
  axes();
  glPopMatrix();
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
  int error = glGetError();
  if ( error )
    printf("%d\n",error);
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostRedisplay();
    else
    switch ( key ) {
      case 'e'  : tx += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'E'  : tx -= 0.1F;
                  if ( tx < 0.1F )
                    tx = 0.1F;
                  glutPostRedisplay();
                  break;
      case 'r'  : ty += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'R'  : ty -= 0.1F;
                  if ( ty < 0.1F )
                    ty = 0.1F;
                  glutPostRedisplay();
                  break;
      case 't'  : tz += 0.1F;
                  glutPostRedisplay();
                  break;
      case 'T'  : tz -= 0.1F;
                  if ( tz < 0.1F )
                    tz = 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 glOrtho");
  myinit();
  creationMenuBasique();
  setParametresOrthoBasique(-4.5,4.5,-4.5,4.5,-100.0,100.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