132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-2003, Silicon Graphics, Inc. 332001f49Smrg * All Rights Reserved 432001f49Smrg * 532001f49Smrg * Permission to use, copy, modify, and distribute this software for any 632001f49Smrg * purpose and without fee is hereby granted, provided that the above 732001f49Smrg * copyright notice appear in all copies and that both the copyright 832001f49Smrg * notice and this permission notice appear in supporting documentation, 932001f49Smrg * and that the name of Silicon Graphics, Inc. not be used in 1032001f49Smrg * advertising or publicity pertaining to distribution of the software 1132001f49Smrg * without specific, written prior permission. 1232001f49Smrg * 1332001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND 1432001f49Smrg * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1532001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1632001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1732001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1832001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 1932001f49Smrg * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF 2032001f49Smrg * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD 2132001f49Smrg * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF 2232001f49Smrg * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF 2332001f49Smrg * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE 2432001f49Smrg * OR PERFORMANCE OF THIS SOFTWARE. 2532001f49Smrg * 2632001f49Smrg * US Government Users Restricted Rights 2732001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2832001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2932001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 3032001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor clauses 3132001f49Smrg * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights 3232001f49Smrg * reserved under the copyright laws of the United States. 3332001f49Smrg * 3432001f49Smrg * Contractor/manufacturer is: 3532001f49Smrg * Silicon Graphics, Inc. 3632001f49Smrg * 1500 Crittenden Lane 3732001f49Smrg * Mountain View, CA 94043 3832001f49Smrg * United State of America 3932001f49Smrg * 4032001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 4132001f49Smrg */ 4232001f49Smrg 4332001f49Smrg/* 4432001f49Smrg * fogcoord.c 4532001f49Smrg * 4632001f49Smrg * This program demonstrates the use of explicit fog 4732001f49Smrg * coordinates. You can press the keyboard and change 4832001f49Smrg * the fog coordinate value at any vertex. You can 4932001f49Smrg * also switch between using explicit fog coordinates 5032001f49Smrg * and the default fog generation mode. 5132001f49Smrg * 5232001f49Smrg * Pressing the 'f' and 'b' keys move the viewer forward 5332001f49Smrg * and backwards. 5432001f49Smrg * Pressing 'c' initiates the default fog generation. 5532001f49Smrg * Pressing capital 'C' restores explicit fog coordinates. 5632001f49Smrg * Pressing '1', '2', '3', '8', '9', and '0' add or 5732001f49Smrg * subtract from the fog coordinate values at one of the 5832001f49Smrg * three vertices of the triangle. 5932001f49Smrg */ 6032001f49Smrg 6132001f49Smrg#include <GL/glew.h> 6232001f49Smrg#include "glut_wrap.h" 6332001f49Smrg#include <math.h> 6432001f49Smrg#include <stdlib.h> 6532001f49Smrg#include <stdio.h> 6632001f49Smrg 6732001f49Smrgstatic GLfloat f1, f2, f3; 6832001f49Smrg 6932001f49Smrg/* Initialize fog 7032001f49Smrg */ 7132001f49Smrgstatic void init(void) 7232001f49Smrg{ 7332001f49Smrg GLfloat fogColor[4] = {0.0, 0.25, 0.25, 1.0}; 7432001f49Smrg f1 = 1.0f; 7532001f49Smrg f2 = 5.0f; 7632001f49Smrg f3 = 10.0f; 7732001f49Smrg 7832001f49Smrg glEnable(GL_FOG); 7932001f49Smrg glFogi (GL_FOG_MODE, GL_EXP); 8032001f49Smrg glFogfv (GL_FOG_COLOR, fogColor); 8132001f49Smrg glFogf (GL_FOG_DENSITY, 0.25); 8232001f49Smrg glHint (GL_FOG_HINT, GL_DONT_CARE); 8332001f49Smrg glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); 8432001f49Smrg glClearColor(0.0, 0.25, 0.25, 1.0); /* fog color */ 8532001f49Smrg} 8632001f49Smrg 8732001f49Smrg/* display() draws a triangle at an angle. 8832001f49Smrg */ 8932001f49Smrgstatic void display(void) 9032001f49Smrg{ 9132001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 9232001f49Smrg 9332001f49Smrg glColor3f (1.0f, 0.75f, 0.0f); 9432001f49Smrg glBegin (GL_TRIANGLES); 9532001f49Smrg glFogCoordfEXT (f1); 9632001f49Smrg glVertex3f (2.0f, -2.0f, 0.0f); 9732001f49Smrg glFogCoordfEXT (f2); 9832001f49Smrg glVertex3f (-2.0f, 0.0f, -5.0f); 9932001f49Smrg glFogCoordfEXT (f3); 10032001f49Smrg glVertex3f (0.0f, 2.0f, -10.0f); 10132001f49Smrg glEnd(); 10232001f49Smrg 10332001f49Smrg glutSwapBuffers(); 10432001f49Smrg} 10532001f49Smrg 10632001f49Smrgstatic void reshape(int w, int h) 10732001f49Smrg{ 10832001f49Smrg glViewport(0, 0, (GLsizei) w, (GLsizei) h); 10932001f49Smrg glMatrixMode(GL_PROJECTION); 11032001f49Smrg glLoadIdentity(); 11132001f49Smrg gluPerspective (45.0, 1.0, 0.25, 25.0); 11232001f49Smrg glMatrixMode(GL_MODELVIEW); 11332001f49Smrg glLoadIdentity (); 11432001f49Smrg glTranslatef (0.0, 0.0, -5.0); 11532001f49Smrg} 11632001f49Smrg 11732001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 11832001f49Smrg{ 11932001f49Smrg switch (key) { 12032001f49Smrg case 'c': 12132001f49Smrg glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT); 12232001f49Smrg glutPostRedisplay(); 12332001f49Smrg break; 12432001f49Smrg case 'C': 12532001f49Smrg glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT); 12632001f49Smrg glutPostRedisplay(); 12732001f49Smrg break; 12832001f49Smrg case '1': 12932001f49Smrg f1 = f1 + 0.25; 13032001f49Smrg glutPostRedisplay(); 13132001f49Smrg break; 13232001f49Smrg case '2': 13332001f49Smrg f2 = f2 + 0.25; 13432001f49Smrg glutPostRedisplay(); 13532001f49Smrg break; 13632001f49Smrg case '3': 13732001f49Smrg f3 = f3 + 0.25; 13832001f49Smrg glutPostRedisplay(); 13932001f49Smrg break; 14032001f49Smrg case '8': 14132001f49Smrg if (f1 > 0.25) { 14232001f49Smrg f1 = f1 - 0.25; 14332001f49Smrg glutPostRedisplay(); 14432001f49Smrg } 14532001f49Smrg break; 14632001f49Smrg case '9': 14732001f49Smrg if (f2 > 0.25) { 14832001f49Smrg f2 = f2 - 0.25; 14932001f49Smrg glutPostRedisplay(); 15032001f49Smrg } 15132001f49Smrg break; 15232001f49Smrg case '0': 15332001f49Smrg if (f3 > 0.25) { 15432001f49Smrg f3 = f3 - 0.25; 15532001f49Smrg glutPostRedisplay(); 15632001f49Smrg } 15732001f49Smrg break; 15832001f49Smrg case 'b': 15932001f49Smrg glMatrixMode (GL_MODELVIEW); 16032001f49Smrg glTranslatef (0.0, 0.0, -0.25); 16132001f49Smrg glutPostRedisplay(); 16232001f49Smrg break; 16332001f49Smrg case 'f': 16432001f49Smrg glMatrixMode (GL_MODELVIEW); 16532001f49Smrg glTranslatef (0.0, 0.0, 0.25); 16632001f49Smrg glutPostRedisplay(); 16732001f49Smrg break; 16832001f49Smrg case 27: 16932001f49Smrg exit(0); 17032001f49Smrg break; 17132001f49Smrg default: 17232001f49Smrg break; 17332001f49Smrg } 17432001f49Smrg} 17532001f49Smrg 17632001f49Smrg 17732001f49Smrg/* Main Loop 17832001f49Smrg * Open window with initial window size, title bar, 17932001f49Smrg * RGBA display mode, depth buffer, and handle input events. 18032001f49Smrg */ 18132001f49Smrgint main(int argc, char** argv) 18232001f49Smrg{ 18332001f49Smrg glutInit(&argc, argv); 18432001f49Smrg glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); 18532001f49Smrg glutInitWindowSize(500, 500); 18632001f49Smrg glutCreateWindow(argv[0]); 18732001f49Smrg glewInit(); 18832001f49Smrg init(); 18932001f49Smrg glutReshapeFunc (reshape); 19032001f49Smrg glutKeyboardFunc (keyboard); 19132001f49Smrg glutDisplayFunc (display); 19232001f49Smrg glutMainLoop(); 19332001f49Smrg return 0; 19432001f49Smrg} 195