home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 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.
- */
-
- /* show.c
- * Type "show <imageFileName>" to create a window displaying any
- * RGB image stored in the SGI .rgb format.
- *
- * imageFileName is opened and the image data is read.
- * The image is then displayed in a window.
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <math.h>
- #include <stdio.h>
- #include "rgbImageFile.h" /* should be found in ../../include */
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static unsigned int *image;
- static int imageWidth, imageHeight;
-
- void
- main ( int argc, char *argv[])
- {
- glutInit( &argc, argv );
-
- if (argc < 2) {
- fprintf (stderr, "usage: show <imageFileName>\n");
- exit (1);
- }
-
- image = rgbReadImageFile(argv[1], &imageWidth, &imageHeight);
-
- glutInitWindowPosition( 100, 100 );
- glutInitWindowSize( imageWidth, imageHeight );
- glutInitDisplayMode( GLUT_RGBA | GLUT_SINGLE );
- glutCreateWindow( argv[0] );
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- glutMainLoop();
- }
-
- GLvoid
- initgfx( void )
- {
- glClearColor( 0.0, 0.0, 0.0, 1.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 )
- {
- glViewport( 0, 0, width, height );
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- gluOrtho2D( 0.0, (GLdouble) width, 0.0, (GLdouble) height );
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- glTranslatef( 0.375, 0.375, 0.0 );
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- glClear( GL_COLOR_BUFFER_BIT );
-
- /* Set raster position. Note that glRasterPos2i() takes
- * world coordinates, which are transformed by the current
- * MODELVIEW and PROJECTION matrices.
- *
- * In this example, both contain Identity matrices,
- * causing these xy coordinates to map directly to window
- * coordinates. This would not be the case if any
- * projection or modeling transforms had been applied.
- */
- glRasterPos2i( 0, 0 );
- glDrawPixels( imageWidth, imageHeight, GL_RGBA, GL_UNSIGNED_BYTE,
- image );
-
- glFlush();
- }
-