L'exécutable

Le source: Nurbs.cpp

#include <windows.h>

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

#include <math.h>

#define iw 64 
#define ih 64

static float anglex = 0.0F ;
static float angley = 0.0F ;

GLfloat ctlpoints[4][4][3]; 
GLUnurbsObj *theNurb; 
  
void CALLBACK display(void) { 
  GLfloat knots[8] = {0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0}; 
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
  glPushMatrix();
  glTranslatef(0.0F,1.0F,0.0F) ;
  glRotatef(anglex,1.0F,0.0F,0.0F) ;
  glRotatef(angley,0.0F,1.0F,0.0F) ;
  glRotatef(330.0,1.,0.,0.); 
  glScalef(0.5,0.5,0.5); 
  gluBeginSurface(theNurb); 
  gluNurbsSurface(theNurb,8,knots,8,knots,4*3,3,&ctlpoints[0][0][0],4,4,GL_MAP2_VERTEX_3); 
  gluEndSurface(theNurb); 
  glPopMatrix(); 
  glFlush();
  auxSwapBuffers();
} 
  
void init_surface(void) { 
  int u,v; 
  for( u = 0 ; u < 4 ; u++ ) { 
    for( v = 0 ; v < 4 ; v++ ) { 
      ctlpoints[u][v][0] = 3.0F*(u-1.5F); 
      ctlpoints[u][v][1] = 2.0F*(v-1.5F); 
      if ((u==1 || u==2)&&(v==1 || v==2)) 
        ctlpoints[u][v][2] = 3.0; 
        else 
        ctlpoints[u][v][2] = -3.0; } } 
  } 
  
void myinit(void) { 
  GLfloat diffuse[] = { 0.7F,0.7F,0.7F,1.0F }; 
  GLfloat specular[] = { 1.0F,1.0F,1.0F,1.0F }; 
  GLfloat shininess[] = { 100.0F }; 
  glClearColor(0.9,0.8,0.6,1.0); 
  glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse); 
  glMaterialfv(GL_FRONT,GL_SPECULAR,specular); 
  glMaterialfv(GL_FRONT,GL_SHININESS,shininess); 
  glEnable(GL_LIGHTING); 
  glEnable(GL_LIGHT0); 
  glDepthFunc(GL_LESS); 
  glEnable(GL_DEPTH_TEST); 
  glEnable(GL_AUTO_NORMAL); 
  glEnable(GL_NORMALIZE); 
  init_surface(); 
  theNurb = gluNewNurbsRenderer(); 
  gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,25.0); 
  gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL); 
} 
  
void CALLBACK myReshape(int w,int h) { 
  glViewport(0,0,w,h); 
  glMatrixMode(GL_PROJECTION); 
  glLoadIdentity(); 
  gluPerspective(45.0,(float)w/(float)h,3.0,8.0); 
  glMatrixMode(GL_MODELVIEW); 
  glLoadIdentity(); 
  glTranslatef(0.0,0.0,-5.0); 
} 
    
void CALLBACK up(void) {
  anglex-- ;
}

void CALLBACK down(void) {
  anglex++ ;
}

void CALLBACK left(void) {
  angley-- ;
}

void CALLBACK right(void) {
  angley++ ;
}

void main(void) { 
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH); 
  auxInitPosition(0,0,300,230); 
  auxInitWindow("NURB"); 
  myinit(); 
  auxKeyFunc(AUX_UP,up) ;
  auxKeyFunc(AUX_DOWN,down) ;
  auxKeyFunc(AUX_LEFT,left) ;
  auxKeyFunc(AUX_RIGHT,right) ;
  auxReshapeFunc(myReshape); 
  auxMainLoop(display); 
} 
 RETOUR