/* Using fog in a scene. Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 */ #include #include #include #include int FogOption = 0; void fog() { glEnable(GL_FOG); GLfloat fogColor[4]={0.3,0.3,0.3,1}; glFogfv(GL_FOG_COLOR,fogColor); glHint(GL_FOG_HINT,GL_NICEST); switch(FogOption) { case 0: printf("No Fog\n"); glDisable(GL_FOG); break; case 1: printf("Linear Fog\n"); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, 10); glFogf(GL_FOG_END, 60); break; case 2: printf("Exponential Decay Fog\n"); glFogi(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.01); break; case 3: printf("Gaussian Decay Fog\n"); glFogi(GL_FOG_MODE, GL_EXP2); glFogf(GL_FOG_DENSITY, 0.01); break; } } void display(void) { int i; twDisplayInit(0.3,0.3,0.3); twCamera(); fog(); twColorName(TW_GREEN); twGround(); twColorName(TW_MAGENTA); glPushMatrix(); glTranslatef(50,0,50); glScalef(1,40,1); // for tall cubes for(int i=0; i<50; i++) { glutSolidCube(0.5); glTranslatef(-1,0,-1); } glPopMatrix(); glFlush(); glutSwapBuffers(); } void fogToggle(unsigned char k, int, int) { FogOption = (FogOption+1)%4; glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(0,50,0,20,0,50); twMainInit(); twKeyCallback('f',fogToggle,"switch among fog options"); glutMainLoop(); return 0; }