Added ESC key handling
This commit is contained in:
@@ -3,14 +3,14 @@
|
||||
|
||||
/**
|
||||
* (c) Copyright 1993, Silicon Graphics, Inc.
|
||||
* ALL RIGHTS RESERVED
|
||||
* Permission to use, copy, modify, and distribute this software for
|
||||
* ALL RIGHTS RESERVED
|
||||
* Permission to use, copy, modify, and distribute this software for
|
||||
* any purpose and without fee is hereby granted, provided that the above
|
||||
* copyright notice appear in all copies and that both the copyright notice
|
||||
* and this permission notice appear in supporting documentation, and that
|
||||
* and this permission notice appear in supporting documentation, and that
|
||||
* the name of Silicon Graphics, Inc. not be used in advertising
|
||||
* or publicity pertaining to distribution of the software without specific,
|
||||
* written prior permission.
|
||||
* written prior permission.
|
||||
*
|
||||
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
|
||||
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
|
||||
@@ -24,8 +24,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* US Government Users Restricted Rights
|
||||
*
|
||||
* US Government Users Restricted Rights
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
|
||||
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
|
||||
@@ -39,11 +39,11 @@
|
||||
*/
|
||||
/*
|
||||
* fog.c
|
||||
* This program draws 5 red teapots, each at a different
|
||||
* z distance from the eye, in different types of fog.
|
||||
* Pressing the left mouse button chooses between 3 types of
|
||||
* fog: exponential, exponential squared, and linear.
|
||||
* In this program, there is a fixed density value, as well
|
||||
* This program draws 5 red teapots, each at a different
|
||||
* z distance from the eye, in different types of fog.
|
||||
* Pressing the left mouse button chooses between 3 types of
|
||||
* fog: exponential, exponential squared, and linear.
|
||||
* In this program, there is a fixed density value, as well
|
||||
* as fixed start and end values for the linear fog.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
GLint fogMode;
|
||||
|
||||
void
|
||||
void
|
||||
selectFog(int mode)
|
||||
{
|
||||
switch(mode) {
|
||||
@@ -70,10 +70,10 @@ selectFog(int mode)
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize z-buffer, projection matrix, light source,
|
||||
/* Initialize z-buffer, projection matrix, light source,
|
||||
* and lighting model. Do not specify a material property here.
|
||||
*/
|
||||
void
|
||||
void
|
||||
myinit(void)
|
||||
{
|
||||
GLfloat position[] =
|
||||
@@ -106,7 +106,7 @@ myinit(void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
renderRedTeapot(GLfloat x, GLfloat y, GLfloat z)
|
||||
{
|
||||
float mat[4];
|
||||
@@ -133,7 +133,7 @@ renderRedTeapot(GLfloat x, GLfloat y, GLfloat z)
|
||||
|
||||
/* display() draws 5 teapots at different z positions.
|
||||
*/
|
||||
void
|
||||
void
|
||||
display(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -145,7 +145,7 @@ display(void)
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
myReshape(int w, int h)
|
||||
{
|
||||
glViewport(0, 0, w, h);
|
||||
@@ -161,11 +161,24 @@ myReshape(int w, int h)
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
static void
|
||||
key(unsigned char k, int x, int y)
|
||||
{
|
||||
switch (k) {
|
||||
case 27: /* Escape */
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
/* Main Loop
|
||||
* Open window with initial window size, title bar,
|
||||
* Open window with initial window size, title bar,
|
||||
* RGBA display mode, depth buffer, and handle input events.
|
||||
*/
|
||||
int
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
@@ -181,6 +194,7 @@ main(int argc, char **argv)
|
||||
glutAddMenuEntry("Fog LINEAR", GL_LINEAR);
|
||||
glutAddMenuEntry("Quit", 0);
|
||||
glutAttachMenu(GLUT_RIGHT_BUTTON);
|
||||
glutKeyboardFunc(key);
|
||||
glutMainLoop();
|
||||
return 0; /* ANSI C requires main to return int. */
|
||||
}
|
||||
|
Reference in New Issue
Block a user