L'exécutable

Le source: Idle.cpp

#include "windows.h"

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

#include <stdio.h>

static float x = 0.0F ;
static float y = 20.0F ;
static float dx = 1.13F ;
static float dy = 0.97F ;
static float w = 0.0F ;
static float h = 0.0F ;

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[] = { 1.0F,1.0F,1.0F,1.0F };
  GLfloat light_position[] = { 1.0F,1.0F,1.0F,0.0F };
  glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
  glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
  glLightfv(GL_LIGHT0,GL_POSITION,light_position);
  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);
  glPushMatrix();
  glTranslatef(x,y,0.0F);
  auxSolidSphere(10.0);
  glPopMatrix();
  glFlush();
  auxSwapBuffers();
}

void CALLBACK myReshape(int ww,int hh) {
  w =(float) ww ;
  h =(float) hh ;
  glViewport(0,0,ww,hh);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-w/2,w/2,-h/2,h/2,-10.0,10.0);
  glMatrixMode(GL_MODELVIEW);
}

void CALLBACK idle(void) {
  x += dx ;
  y += dy ;
  if ( x < -w/2+10 )
    dx = -dx ;
  if ( y < -h/2+10 )
    dy = -dy ;
  if ( x >= w/2-10 )
    dx = -dx ;
  if ( y >= h/2-10 )
    dy = -dy ;
  display() ;
}

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH);
  auxInitPosition(0,0,300,300);
  auxInitWindow("Une sphère se déplaçant toute seule");
  myinit();
  auxIdleFunc(idle);
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}
 RETOUR