L'exécutable
- Return pour passer d'un affichage à un autre
affichage
- x, X, y, Y, z et Z pour faire tourner les scènes


Le source: Voxels.cpp
#include "windows.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <GL/glut.h>
#include <stdio.h>
#include <math.h>
static GLfloat view_rotx=10.0F ;
static GLfloat view_roty=15.0F ;
static GLfloat view_rotz=0.0F ;
static int aff = 0 ;
void myinit(void) {
GLfloat light_ambient[] = { 0.0F,0.0F,0.0F,1.0F };
GLfloat light_diffuse[] = { 1.0F,1.0F,1.0F,0.5F };
GLfloat light_specular[] = { 1.0F,1.0F,1.0F,1.0F };
GLfloat light_position0[] = { 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_position0);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}
void CALLBACK display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix() ;
glRotatef(view_rotx,1.0,0.0,0.0);
glRotatef(view_roty,0.0,1.0,0.0);
glRotatef(view_rotz,0.0,0.0,1.0);
float blanc[] = { 1.0F,1.0F,1.0F,1.0F };
glColor4fv(blanc) ;
glBegin(GL_LINES) ;
for ( int x = -6 ; x <= 6 ; x += 4 )
for ( int y = -6 ; y <= 6 ; y += 4 ) {
glVertex3i(x,y,-6) ;
glVertex3i(x,y,6) ;
glVertex3i(x,-6,y) ;
glVertex3i(x,6,y) ;
glVertex3i(-6,x,y) ;
glVertex3i(6,x,y) ; }
glEnd() ;
glEnable(GL_LIGHTING);
if ( aff == 1 ) {
glPushMatrix();
glTranslatef(3.0F,2.0F,1.0F);
float rouge[] = { 1.0F,0.0F,0.0F,1.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,rouge) ;
glRotatef(10,1.0,0.0,0.0);
glRotatef(20,0.0,1.0,0.0);
glRotatef(30,0.0,0.0,1.0);
auxSolidSphere(1.3) ;
glPopMatrix();
glPushMatrix();
glTranslatef(-3.0F,4.0F,-3.0F);
float vert[] = { 0.0F,1.0F,0.0F,1.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,vert) ;
glRotatef(-10,1.0,0.0,0.0);
glRotatef(-20,0.0,1.0,0.0);
glRotatef(60,0.0,0.0,1.0);
auxSolidCube(1.9) ;
glPopMatrix();
glPushMatrix();
glTranslatef(-0.0F,-4.0F,-2.0F);
float bleu[] = { 0.0F,0.0F,1.0F,1.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu) ;
glRotatef(10,1.0,0.0,0.0);
glRotatef(20,0.0,1.0,0.0);
glRotatef(60,0.0,0.0,1.0);
auxSolidCone(1.9,2.0) ;
glPopMatrix();
glPushMatrix();
glTranslatef(-2.0F,-4.0F,-4.0F);
float jaune[] = { 1.0F,1.0F,0.0F,1.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,jaune) ;
glRotatef(10,1.0,0.0,0.0);
glRotatef(20,0.0,1.0,0.0);
glRotatef(60,0.0,0.0,1.0);
auxSolidTorus(0.8,1.6) ;
glPopMatrix();
glPushMatrix();
glTranslatef(4.0F,-1.0F,-4.0F);
float magenta[] = { 1.0F,0.0F,1.0F,1.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,magenta) ;
glRotatef(10,1.0,0.0,0.0);
glRotatef(20,0.0,1.0,0.0);
glRotatef(60,0.0,0.0,1.0);
auxSolidTeapot(1.5) ;
glPopMatrix();
glPushMatrix();
glTranslatef(-3.0F,3.0F,4.0F);
float cyan[] = { 0.0F,1.0F,1.0F,1.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,cyan) ;
glRotatef(10,1.0,0.0,0.0);
glRotatef(60,0.0,1.0,0.0);
glRotatef(60,0.0,0.0,1.0);
auxSolidCylinder(0.8,2.5) ;
glPopMatrix(); }
glDisable(GL_LIGHTING);
glPopMatrix() ;
glFlush();
auxSwapBuffers() ;
}
void CALLBACK myReshape(int w,int h) {
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-11,11,-h*11.0/w,h*11.0/w,-15.0,15.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CALLBACK keyx(void) {
view_rotx += 2 ;
}
void CALLBACK keyX(void) {
view_rotx -= 2 ;
}
void CALLBACK keyy(void) {
view_roty += 2 ;
}
void CALLBACK keyY(void) {
view_roty -= 2 ;
}
void CALLBACK keyz(void) {
view_rotz += 2 ;
}
void CALLBACK keyZ(void) {
view_rotz -= 2 ;
}
void CALLBACK keyReturn(void) {
aff = 1-aff ;
}
void main(void) {
auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH);
auxInitPosition(0,0,300,300);
auxInitWindow("Décomposition en voxels");
myinit();
auxKeyFunc(AUX_x,keyx) ;
auxKeyFunc(AUX_X,keyX) ;
auxKeyFunc(AUX_y,keyy) ;
auxKeyFunc(AUX_Y,keyY) ;
auxKeyFunc(AUX_z,keyz) ;
auxKeyFunc(AUX_Z,keyZ) ;
auxKeyFunc(AUX_RETURN,keyReturn) ;
auxReshapeFunc(myReshape);
auxMainLoop(display);
}
RETOUR