且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SGI OpenGL Teapot

更新时间:2022-09-01 18:09:51


SGI OpenGL Teapot 

SGI OpenGL Teapot// Name     : OpenGL Teapot
SGI OpenGL Teapot
// Author   : Terrence Ma
SGI OpenGL Teapot
// Email    : terrence@terrence.com
SGI OpenGL Teapot
// Web      : http://www.terrence.com
SGI OpenGL Teapot
// Date     : 10/25/2001
SGI OpenGL Teapot
// Modified : Tutorial sample from Mesa3d.org (http://www.mesa3d.org)
SGI OpenGL Teapot

SGI OpenGL Teapot/*
SGI OpenGL Teapot * Copyright (c) 1993-1997, Silicon Graphics, Inc.
SGI OpenGL Teapot * ALL RIGHTS RESERVED 
SGI OpenGL Teapot * Permission to use, copy, modify, and distribute this software for 
SGI OpenGL Teapot * any purpose and without fee is hereby granted, provided that the above
SGI OpenGL Teapot * copyright notice appear in all copies and that both the copyright notice
SGI OpenGL Teapot * and this permission notice appear in supporting documentation, and that 
SGI OpenGL Teapot * the name of Silicon Graphics, Inc. not be used in advertising
SGI OpenGL Teapot * or publicity pertaining to distribution of the software without specific,
SGI OpenGL Teapot * written prior permission. 
SGI OpenGL Teapot *
SGI OpenGL Teapot * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
SGI OpenGL Teapot * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
SGI OpenGL Teapot * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
SGI OpenGL Teapot * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
SGI OpenGL Teapot * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
SGI OpenGL Teapot * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
SGI OpenGL Teapot * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
SGI OpenGL Teapot * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
SGI OpenGL Teapot * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
SGI OpenGL Teapot * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
SGI OpenGL Teapot * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
SGI OpenGL Teapot * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
SGI OpenGL Teapot * 
SGI OpenGL Teapot * US Government Users Restricted Rights 
SGI OpenGL Teapot * Use, duplication, or disclosure by the Government is subject to
SGI OpenGL Teapot * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
SGI OpenGL Teapot * (c)(1)(ii) of the Rights in Technical Data and Computer Software
SGI OpenGL Teapot * clause at DFARS 252.227-7013 and/or in similar or successor
SGI OpenGL Teapot * clauses in the FAR or the DOD or NASA FAR Supplement.
SGI OpenGL Teapot * Unpublished-- rights reserved under the copyright laws of the
SGI OpenGL Teapot * United States.  Contractor/manufacturer is Silicon Graphics,
SGI OpenGL Teapot * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
SGI OpenGL Teapot *
SGI OpenGL Teapot * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
SGI OpenGL Teapot 
*/

SGI OpenGL Teapot
SGI OpenGL Teapot/*
SGI OpenGL Teapot *  light.c
SGI OpenGL Teapot *  This program demonstrates the use of the OpenGL lighting
SGI OpenGL Teapot *  model.  A sphere is drawn using a grey material characteristic.
SGI OpenGL Teapot *  A single light source illuminates the object.
SGI OpenGL Teapot 
*/

SGI OpenGL Teapot#include <GL/glut.h>
SGI OpenGL Teapot#include <stdlib.h>
SGI OpenGL Teapot
SGI OpenGL Teapot/*  Initialize material property, light source, lighting model,
SGI OpenGL Teapot *  and depth buffer.
SGI OpenGL Teapot 
*/

SGI OpenGL Teapotvoid init(void
SGI OpenGL Teapot{
SGI OpenGL Teapot   GLfloat mat_specular[] = { 3000.0, 3000.0, 3000.0, 3000.0 };
SGI OpenGL Teapot   GLfloat mat_shininess[] = { 100.0 };
SGI OpenGL Teapot   GLfloat mat_surface[] = { 1.0, 1.0, 0.0, 0.0 };
SGI OpenGL Teapot
SGI OpenGL Teapot   GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
SGI OpenGL Teapot   GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
SGI OpenGL Teapot   GLfloat light_position1[] = { -1.0, -1.0, 1.0, 0.0 };
SGI OpenGL Teapot
SGI OpenGL Teapot   glClearColor (0.0, 0.0, 0.0, 0.0);
SGI OpenGL Teapot   glShadeModel (GL_SMOOTH);
SGI OpenGL Teapot
SGI OpenGL Teapot   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
SGI OpenGL Teapot   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
SGI OpenGL Teapot   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_surface);
SGI OpenGL Teapot
SGI OpenGL Teapot   glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
SGI OpenGL Teapot   glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
SGI OpenGL Teapot   glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
SGI OpenGL Teapot   glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
SGI OpenGL Teapot   glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light);
SGI OpenGL Teapot   glLightfv(GL_LIGHT1, GL_SPECULAR, white_light);
SGI OpenGL Teapot
SGI OpenGL Teapot   glEnable(GL_LIGHTING);
SGI OpenGL Teapot   glEnable(GL_LIGHT0);
SGI OpenGL Teapot   glEnable(GL_LIGHT1);
SGI OpenGL Teapot   glEnable(GL_DEPTH_TEST);
SGI OpenGL Teapot}

SGI OpenGL Teapot
SGI OpenGL Teapotvoid display(void)
SGI OpenGL Teapot{
SGI OpenGL Teapot   gluLookAt (6.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
SGI OpenGL Teapot   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SGI OpenGL Teapot   glutSolidTeapot (0.80);
SGI OpenGL Teapot   glFlush ();
SGI OpenGL Teapot}

SGI OpenGL Teapot
SGI OpenGL Teapotvoid reshape (int w, int h)
SGI OpenGL Teapot{
SGI OpenGL Teapot   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
SGI OpenGL Teapot   glMatrixMode (GL_PROJECTION);
SGI OpenGL Teapot   glLoadIdentity();
SGI OpenGL Teapot   if (w <= h)
SGI OpenGL Teapot      glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
SGI OpenGL Teapot         1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
SGI OpenGL Teapot   else
SGI OpenGL Teapot      glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
SGI OpenGL Teapot         1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
SGI OpenGL Teapot   glMatrixMode(GL_MODELVIEW);
SGI OpenGL Teapot   glLoadIdentity();
SGI OpenGL Teapot}

SGI OpenGL Teapot
SGI OpenGL Teapot/* ARGSUSED1 */
SGI OpenGL Teapotvoid keyboard(unsigned char key, int x, int y)
SGI OpenGL Teapot{
SGI OpenGL Teapot   switch (key) {
SGI OpenGL Teapot      case 27:
SGI OpenGL Teapot         exit(0);
SGI OpenGL Teapot         break;
SGI OpenGL Teapot   }

SGI OpenGL Teapot}

SGI OpenGL Teapot
SGI OpenGL Teapotint main(int argc, char** argv)
SGI OpenGL Teapot{
SGI OpenGL Teapot   glutInit(&argc, argv);
SGI OpenGL Teapot   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
SGI OpenGL Teapot   glutInitWindowSize (400, 400); 
SGI OpenGL Teapot   glutInitWindowPosition (100, 100);
SGI OpenGL Teapot   glutCreateWindow ("OpenGL Teapot");
SGI OpenGL Teapot   init ();
SGI OpenGL Teapot   glutDisplayFunc(display); 
SGI OpenGL Teapot   glutReshapeFunc(reshape);
SGI OpenGL Teapot   glutKeyboardFunc(keyboard);
SGI OpenGL Teapot   glutMainLoop();
SGI OpenGL Teapot   return 0;
SGI OpenGL Teapot}