Added ESC key handling

This commit is contained in:
Ted Jump
1999-09-17 02:40:51 +00:00
parent 74783e9936
commit 83c02efa52
30 changed files with 799 additions and 414 deletions

View File

@@ -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,19 +39,19 @@
*/
/*
* pickdepth.c
* Picking is demonstrated in this program. In
* rendering mode, three overlapping rectangles are
* drawn. When the left mouse button is pressed,
* selection mode is entered with the picking matrix.
* Picking is demonstrated in this program. In
* rendering mode, three overlapping rectangles are
* drawn. When the left mouse button is pressed,
* selection mode is entered with the picking matrix.
* Rectangles which are drawn under the cursor position
* are "picked." Pay special attention to the depth
* are "picked." Pay special attention to the depth
* value range, which is returned.
*/
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
void
void
myinit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
@@ -61,11 +61,11 @@ myinit(void)
glDepthRange(0.0, 1.0); /* The default z mapping */
}
/* The three rectangles are drawn. In selection mode,
* each rectangle is given the same name. Note that
/* The three rectangles are drawn. In selection mode,
* each rectangle is given the same name. Note that
* each rectangle is drawn with a different z value.
*/
void
void
drawRects(GLenum mode)
{
if (mode == GL_SELECT)
@@ -97,10 +97,10 @@ drawRects(GLenum mode)
glEnd();
}
/* processHits() prints out the contents of the
/* processHits() prints out the contents of the
* selection array.
*/
void
void
processHits(GLint hits, GLuint buffer[])
{
unsigned int i, j;
@@ -125,13 +125,13 @@ processHits(GLint hits, GLuint buffer[])
}
}
/* pickRects() sets up selection mode, name stack,
* and projection matrix for picking. Then the objects
/* pickRects() sets up selection mode, name stack,
* and projection matrix for picking. Then the objects
* are drawn.
*/
#define BUFSIZE 512
void
void
pickRects(int button, int state, int x, int y)
{
GLuint selectBuf[BUFSIZE];
@@ -164,7 +164,7 @@ pickRects(int button, int state, int x, int y)
processHits(hits, selectBuf);
}
void
void
display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -172,7 +172,7 @@ display(void)
glutSwapBuffers();
}
void
void
myReshape(int w, int h)
{
glViewport(0, 0, w, h);
@@ -183,8 +183,21 @@ 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
@@ -198,6 +211,7 @@ main(int argc, char **argv)
glutMouseFunc(pickRects);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}