L'exécutable

Le source: Sauvegarde.cpp

#include <windows.h>

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

#include <stdio.h>

static int ww ;
static int hh ;

void myinit(void) {
  GLfloat specular[] = { 1.0,1.0,1.0,1.0 };
  GLfloat shinines[] = { 50.0 };
  GLfloat l_pos[] = { 1.0,1.0,1.0,0.0 };
  glClearColor(0.5,0.5,1.0,1.0) ;
  glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
  glMaterialfv(GL_FRONT,GL_SHININESS,shinines);
  glLightfv(GL_LIGHT0,GL_POSITION,l_pos);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glDepthFunc(GL_LESS);
  glEnable(GL_DEPTH_TEST);
}

void CALLBACK display(void) {
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  auxSolidSphere(1.0);
  glFlush();
}

void CALLBACK myReshape(int w,int h) {
  glViewport(0,0,w,h);
  ww = w ;
  hh = h ;
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  if (w <= h)
    glOrtho(-1.5,1.5,-1.5*(float)h/(float)w,1.5*(float)h/(float)w,-10.,10.);
    else
    glOrtho(-1.5*(float)w/(float)h,1.5*(float)w/(float)h,-1.5,1.5,-10.,10.);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void sauve(char *nom,int px,int py,int dx,int dy) {
  GLubyte *image ;
  FILE *num ;
  int y,x ;
  image =(GLubyte *) calloc(dx*dy*3,sizeof(GLubyte)); 
  glReadPixels(px,py,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,image); 
  num = fopen(nom,"wb") ;
  if ( num ) {
    for ( y = dy-1 ; y >= 0 ; y-- ) {
      for ( x = 0 ; x < dx ; x++ ) {
        fwrite((void *) &image[(y*dx+x)*3],sizeof(GLubyte),3,num) ; } }
    fclose(num) ; }
  free(image) ;
}

void CALLBACK keyS(void) {
  sauve("image.raw",0,0,ww,hh) ;
}

void main(void) {
  auxInitDisplayMode(AUX_SINGLE|AUX_RGB|AUX_DEPTH);
  auxInitPosition(0,0,256,256);
  auxInitWindow("Sphère blanche");
  myinit();
  auxKeyFunc(AUX_S,keyS) ;
  auxKeyFunc(AUX_s,keyS) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}
 RETOUR