SGI OpenGL Color Cube

OpenGL Color Cube
None.gif //  Name     : OpenGL Color Cube
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 *  aapoly.c
InBlock.gif *  This program draws filled polygons with antialiased
InBlock.gif *  edges.  The special GL_SRC_ALPHA_SATURATE blending 
InBlock.gif *  function is used.
InBlock.gif *  Pressing the 't' key turns the antialiasing on and off.
ExpandedBlockEnd.gif 
*/
None.gif#include <GL/glut.h>
None.gif#include <stdlib.h>
None.gif#include <stdio.h>
None.gif#include < string.h>
None.gif
None.gifGLboolean polySmooth = GL_TRUE;
None.gif
None.gif static  void init( void)
ExpandedBlockStart.gif {
InBlock.gif   glCullFace (GL_BACK);
InBlock.gif   glEnable (GL_CULL_FACE);
InBlock.gif   glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
InBlock.gif   glClearColor (0.0, 0.0, 0.0, 0.0);
ExpandedBlockEnd.gif}
None.gif
None.gif #define NFACE 6
None.gif #define NVERT 8
None.gif void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1,
None.gif        GLdouble z0, GLdouble z1)
ExpandedBlockStart.gif {
InBlock.gif   static GLfloat v[8][3];
ExpandedSubBlockStart.gif   static GLfloat c[8][4] = {
ExpandedSubBlockStart.gif      {0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 1.0},
ExpandedSubBlockStart.gif      {0.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0},
ExpandedSubBlockStart.gif      {0.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 1.0, 1.0},
ExpandedSubBlockStart.gif      {0.0, 1.0, 1.0, 1.0}, {1.0, 1.0, 1.0, 1.0}
ExpandedSubBlockEnd.gif   };
InBlock.gif
ExpandedSubBlockStart.gif/*  indices of front, top, left, bottom, right, back faces  */
ExpandedSubBlockStart.gif   static GLubyte indices[NFACE][4] = {
ExpandedSubBlockStart.gif      {4, 5, 6, 7}, {2, 3, 7, 6}, {0, 4, 7, 3},
ExpandedSubBlockStart.gif      {0, 1, 5, 4}, {1, 5, 6, 2}, {0, 3, 2, 1}
ExpandedSubBlockEnd.gif   };
InBlock.gif
InBlock.gif   v[0][0] = v[3][0] = v[4][0] = v[7][0] = x0;
InBlock.gif   v[1][0] = v[2][0] = v[5][0] = v[6][0] = x1;
InBlock.gif   v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
InBlock.gif   v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
InBlock.gif   v[0][2] = v[1][2] = v[2][2] = v[3][2] = z0;
InBlock.gif   v[4][2] = v[5][2] = v[6][2] = v[7][2] = z1;
InBlock.gif
InBlock.gif#ifdef GL_VERSION_1_1
InBlock.gif   glEnableClientState (GL_VERTEX_ARRAY);
InBlock.gif   glEnableClientState (GL_COLOR_ARRAY);
InBlock.gif   glVertexPointer (3, GL_FLOAT, 0, v);
InBlock.gif   glColorPointer (4, GL_FLOAT, 0, c);
InBlock.gif   glDrawElements (GL_QUADS, NFACE*4, GL_UNSIGNED_BYTE, indices);
InBlock.gif   glDisableClientState (GL_VERTEX_ARRAY);
InBlock.gif   glDisableClientState (GL_COLOR_ARRAY);
InBlock.gif#else
InBlock.gif   printf ("If this is GL Version 1.0, ");
InBlock.gif   printf ("vertex arrays are not supported.\n");
InBlock.gif   exit(1);
InBlock.gif#endif
ExpandedBlockEnd.gif}
None.gif
ExpandedBlockStart.gif /*  Note:  polygons must be drawn from front to back
InBlock.gif *  for proper blending.
ExpandedBlockEnd.gif 
*/
None.gif void display( void)
ExpandedBlockStart.gif {
ExpandedSubBlockStart.gif   if (polySmooth) {
InBlock.gif      glClear (GL_COLOR_BUFFER_BIT);
InBlock.gif      glEnable (GL_BLEND);
InBlock.gif      glEnable (GL_POLYGON_SMOOTH);
InBlock.gif      glDisable (GL_DEPTH_TEST);
ExpandedSubBlockEnd.gif   }
ExpandedSubBlockStart.gif   else { 
InBlock.gif      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
InBlock.gif      glDisable (GL_BLEND);
InBlock.gif      glDisable (GL_POLYGON_SMOOTH);
InBlock.gif      glEnable (GL_DEPTH_TEST);
ExpandedSubBlockEnd.gif   }
InBlock.gif
InBlock.gif   glPushMatrix ();
InBlock.gif      glTranslatef (0.0, 0.0, -8.0);    
InBlock.gif      glRotatef (30.0, 1.0, 0.0, 0.0);
InBlock.gif      glRotatef (60.0, 0.0, 1.0, 0.0); 
InBlock.gif      drawCube(-0.8, 0.8, -0.8, 0.8, -0.8, 0.8);
InBlock.gif   glPopMatrix ();
InBlock.gif
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   gluPerspective(30.0, (GLfloat) w/(GLfloat) h, 1.0, 20.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 't':
InBlock.gif      case 'T':
InBlock.gif         polySmooth = !polySmooth;
InBlock.gif         glutPostRedisplay();
InBlock.gif         break;
InBlock.gif      case 27:
ExpandedSubBlockStart.gif         exit(0);  /*  Escape key  */
InBlock.gif         break;
InBlock.gif      default:
InBlock.gif         break;
ExpandedSubBlockEnd.gif   }
ExpandedBlockEnd.gif}
None.gif
ExpandedBlockStart.gif /*  Main Loop
ExpandedBlockEnd.gif 
*/
None.gif int main( int argc,  char** argv)
ExpandedBlockStart.gif {
InBlock.gif   glutInit(&argc, argv);
InBlock.gif   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB 
InBlock.gif                        | GLUT_ALPHA | GLUT_DEPTH);
InBlock.gif   glutInitWindowSize(400, 400);
InBlock.gif   glutCreateWindow("OpenGL Color Cube");
InBlock.gif   init ();
InBlock.gif   glutReshapeFunc (reshape);
InBlock.gif   glutKeyboardFunc (keyboard);
InBlock.gif   glutDisplayFunc (display);
InBlock.gif   glutMainLoop();
InBlock.gif   return 0;
ExpandedBlockEnd.gif}
None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值