home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1995, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* blur.c
- * This program demonstrates using the accumulation buffer for
- * effects like motion blur.
- *
- * Escape key - exit the program
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <math.h>
- #include <stdio.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid animate( GLvoid );
- GLvoid visibility( GLint );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- GLvoid printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static GLfloat incAngle, azimAngle, distance;
- static GLint xStart, yStart;
-
- static GLfloat spin = 0.0;
-
- GLvoid
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( width/4, height/4 );
- glutInitWindowSize( width/4, height/4 );
- glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_ACCUM );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutIdleFunc( animate );
- glutVisibilityFunc( visibility );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- GLvoid
- printHelp( char *progname )
- {
- fprintf(stdout,
- "\n%s - motion blurring using the accumulation buffer\n\n"
- "Expect it to run very slowly on systems without \n"
- "a hardware accumulation buffer.\n\n"
- "Escape key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( void )
- {
- static GLfloat mat_ambient[] = { 0.25, 0.05, 0.4, 1.0 };
- static GLfloat mat_diffuse[] = { 0.5, 0.1, 0.8, 1.0 };
- static GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
- static GLfloat mat_shininess[] = { 10.0 };
-
- static GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
- static GLfloat lmodel_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
-
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
-
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
-
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
-
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
-
- glClearAccum( 0.0, 0.0, 0.0, 0.0 );
- glClear( GL_ACCUM_BUFFER_BIT );
-
- glEnable( GL_DEPTH_TEST );
- glEnable( GL_CULL_FACE );
-
- distance = 4.5;
- incAngle = 25.0;
- azimAngle = 0.0;
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit whenever the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height );
-
- aspect = (GLdouble) width / (GLdouble) height;
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- gluPerspective( 45.0, aspect, 3.0, 7.0 );
- glMatrixMode( GL_MODELVIEW );
-
- glClear( GL_ACCUM_BUFFER_BIT );
- }
-
- GLvoid
- animate( GLvoid )
- {
- spin = fmodf( spin + 10.0, 360.0 ); /* update spin */
- glutPostRedisplay(); /* Tell GLUT to redraw */
- }
-
- GLvoid
- visibility( int state )
- {
- if (state == GLUT_VISIBLE) {
- glutIdleFunc( animate );
- } else {
- glutIdleFunc( NULL );
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat decayFactor = 0.5;
-
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- glPushMatrix();
-
- glTranslatef( 0.0, 0.0, -distance);
- glRotatef( incAngle, 1.0, 0.0, 0.0 );
- glRotatef( azimAngle, 0.0, 0.0, 1.0 );
-
- glPushMatrix();
- glAccum( GL_MULT, decayFactor );
- glRotatef( spin, 0.0, 1.0, 0.0 );
- glTranslatef( 1.0, 0.0, 0.0 );
- glutSolidSphere( 0.5, 15, 15 );
- glAccum( GL_ACCUM, (1.0-decayFactor) );
- glAccum( GL_RETURN, 1.0 );
- glPopMatrix();
-
- glPopMatrix();
-
- glutSwapBuffers();
- }
-