SGI OpenGL Teapot


OpenGL Teapot  

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

ExpandedBlockStart.gif /*
InBlock.gif * Copyright (c) 1993-1997, Silicon Graphics, Inc.
InBlock.gif * ALL RIGHTS RESERVED 
InBlock.gif * Permission to use, copy, modify, and distribute this software for 
InBlock.gif * any purpose and without fee is hereby granted, provided that the above
InBlock.gif * copyright notice appear in all copies and that both the copyright notice
InBlock.gif * and this permission notice appear in supporting documentation, and that 
InBlock.gif * the name of Silicon Graphics, Inc. not be used in advertising
InBlock.gif * or publicity pertaining to distribution of the software without specific,
InBlock.gif * written prior permission. 
InBlock.gif *
InBlock.gif * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
InBlock.gif * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
InBlock.gif * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
InBlock.gif * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
InBlock.gif * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
InBlock.gif * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
InBlock.gif * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
InBlock.gif * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
InBlock.gif * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
InBlock.gif * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
InBlock.gif * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
InBlock.gif * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
InBlock.gif * 
InBlock.gif * US Government Users Restricted Rights 
InBlock.gif * Use, duplication, or disclosure by the Government is subject to
InBlock.gif * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
InBlock.gif * (c)(1)(ii) of the Rights in Technical Data and Computer Software
InBlock.gif * clause at DFARS 252.227-7013 and/or in similar or successor
InBlock.gif * clauses in the FAR or the DOD or NASA FAR Supplement.
InBlock.gif * Unpublished-- rights reserved under the copyright laws of the
InBlock.gif * United States.  Contractor/manufacturer is Silicon Graphics,
InBlock.gif * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
InBlock.gif *
InBlock.gif * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
ExpandedBlockEnd.gif 
*/
None.gif
ExpandedBlockStart.gif /*
InBlock.gif *  light.c
InBlock.gif *  This program demonstrates the use of the OpenGL lighting
InBlock.gif *  model.  A sphere is drawn using a grey material characteristic.
InBlock.gif *  A single light source illuminates the object.
ExpandedBlockEnd.gif 
*/
None.gif#include <GL/glut.h>
None.gif#include <stdlib.h>
None.gif
ExpandedBlockStart.gif /*  Initialize material property, light source, lighting model,
InBlock.gif *  and depth buffer.
ExpandedBlockEnd.gif 
*/
None.gif void init( void
ExpandedBlockStart.gif {
ExpandedSubBlockStart.gif   GLfloat mat_specular[] = { 3000.0, 3000.0, 3000.0, 3000.0 };
ExpandedSubBlockStart.gif   GLfloat mat_shininess[] = { 100.0 };
ExpandedSubBlockStart.gif   GLfloat mat_surface[] = { 1.0, 1.0, 0.0, 0.0 };
InBlock.gif
ExpandedSubBlockStart.gif   GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
ExpandedSubBlockStart.gif   GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
ExpandedSubBlockStart.gif   GLfloat light_position1[] = { -1.0, -1.0, 1.0, 0.0 };
InBlock.gif
InBlock.gif   glClearColor (0.0, 0.0, 0.0, 0.0);
InBlock.gif   glShadeModel (GL_SMOOTH);
InBlock.gif
InBlock.gif   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
InBlock.gif   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
InBlock.gif   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_surface);
InBlock.gif
InBlock.gif   glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
InBlock.gif   glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
InBlock.gif   glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
InBlock.gif   glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
InBlock.gif   glLightfv(GL_LIGHT1, GL_DIFFUSE, white_light);
InBlock.gif   glLightfv(GL_LIGHT1, GL_SPECULAR, white_light);
InBlock.gif
InBlock.gif   glEnable(GL_LIGHTING);
InBlock.gif   glEnable(GL_LIGHT0);
InBlock.gif   glEnable(GL_LIGHT1);
InBlock.gif   glEnable(GL_DEPTH_TEST);
ExpandedBlockEnd.gif}
None.gif
None.gif void display( void)
ExpandedBlockStart.gif {
InBlock.gif   gluLookAt (6.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
InBlock.gif   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
InBlock.gif   glutSolidTeapot (0.80);
InBlock.gif   glFlush ();
ExpandedBlockEnd.gif}
None.gif
None.gif void reshape ( int w,  int h)
ExpandedBlockStart.gif {
InBlock.gif   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
InBlock.gif   glMatrixMode (GL_PROJECTION);
InBlock.gif   glLoadIdentity();
InBlock.gif   if (w <= h)
InBlock.gif      glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w,
InBlock.gif         1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
InBlock.gif   else
InBlock.gif      glOrtho (-1.5*(GLfloat)w/(GLfloat)h,
InBlock.gif         1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
InBlock.gif   glMatrixMode(GL_MODELVIEW);
InBlock.gif   glLoadIdentity();
ExpandedBlockEnd.gif}
None.gif
ExpandedBlockStart.gif /* ARGSUSED1 */
None.gif void keyboard(unsigned  char key,  int x,  int y)
ExpandedBlockStart.gif {
ExpandedSubBlockStart.gif   switch (key) {
InBlock.gif      case 27:
InBlock.gif         exit(0);
InBlock.gif         break;
ExpandedSubBlockEnd.gif   }
ExpandedBlockEnd.gif}
None.gif
None.gif int main( int argc,  char** argv)
ExpandedBlockStart.gif {
InBlock.gif   glutInit(&argc, argv);
InBlock.gif   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
InBlock.gif   glutInitWindowSize (400, 400); 
InBlock.gif   glutInitWindowPosition (100, 100);
InBlock.gif   glutCreateWindow ("OpenGL Teapot");
InBlock.gif   init ();
InBlock.gif   glutDisplayFunc(display); 
InBlock.gif   glutReshapeFunc(reshape);
InBlock.gif   glutKeyboardFunc(keyboard);
InBlock.gif   glutMainLoop();
InBlock.gif   return 0;
ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值