#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
GLsizei w, h;
GLfloat fogColor [4] = {1.0, 1.0, 0.5, 1.0};
void init (void) {
glClearColor (1.0, 1.0, 0.5, 1.0);
glShadeModel (GL_SMOOTH);
glEnable (GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (30, 1.0, .1, 15);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
// Initialisation du blending + lissage
glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST);
glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
glLineWidth (1.5);
glEnable (GL_LINE_SMOOTH);
// glEnable (GL_POLYGON_SMOOTH); // <<<======================= Ligne I
glEnable (GL_BLEND); // <<<===================================== Ligne II
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Initialisation du fog
glFogi (GL_FOG_MODE, GL_EXP);
glFogf (GL_FOG_DENSITY, .5);
glFogfv (GL_FOG_COLOR, fogColor);
glHint (GL_FOG_HINT, GL_FASTEST);
glFogf (GL_FOG_START, 1.0);
glFogf (GL_FOG_END, 5.0);
glEnable (GL_FOG); // <<<======================================= Ligne III
}
void display (void) {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Transformation de visualisation
glPushMatrix ();
glRotatef (0, 0, 1, 0);
glTranslatef (0, 0, -9);
glDepthMask (GL_FALSE);
// Dessine 2 lignes croisees
glColor4f (1.0, .0, 1.0, 1.0);
glBegin (GL_LINES);
glVertex3f (-.5, -.5, 0);
glVertex3f (1.5, .5, 0);
glVertex3f (.5, -.5, 0);
glVertex3f (-1.5, .5, 0);
glEnd ();
glPushMatrix ();
glColor4f (1.0, .0, .5, .4);
glTranslatef (1.75, 0, -1.0);
// Dessine le triangle
glPushMatrix ();
glTranslatef (-1.5, 0.0, 0);
glBegin (GL_TRIANGLES);
glVertex3f (-.5, -.5, 0);
glVertex3f (.5, -.5, 0);
glVertex3f (0, .5, 0);
glEnd ();
glPopMatrix ();
// Dessine 3 spheres
glutSolidSphere (1.0, 20, 16);
glTranslatef (-1.5, 0, -1.5);
glTranslatef (-1.5, 0, -1.5);
glutSolidSphere (1.0, 20, 16);
glTranslatef (-1.5, 0, -1.5);
glutSolidSphere (1.0, 20, 16);
glPopMatrix ();
glPopMatrix ();
glDepthMask (GL_TRUE);
glutSwapBuffers ();
}
int main (int argc, char ** argv) {
w = 400;
h = 400;
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (w, h);
glutInitWindowPosition (0, 0);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Partager