home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / opengl / siggraphCD / lib / libaux / teapot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.7 KB  |  162 lines

  1. /*
  2.  * (c) Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #include <GL/gl.h>
  38. #include "aux.h"
  39. #include "teapot.h"
  40.  
  41. #if defined(__cplusplus) || defined(c_plusplus)
  42. #define class c_class
  43. #endif
  44.  
  45. long GRD;
  46.  
  47. #define TEAPOTSOLID 0
  48. #define TEAPOTWIRE 1
  49.  
  50. static GLuint teapots[2] = {0, 0};
  51.  
  52. static float tex[2][2][2] = {{{0, 0},{1, 0}},{{0, 1},{1, 1}}};
  53.  
  54. static void solidTeapot(long grid, GLdouble scale)
  55. {
  56.     float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
  57.     long i, j, k, l;
  58.  
  59.     if (grid < 2) grid = 7;
  60.     GRD = grid;
  61.     teapots[TEAPOTSOLID] = glGenLists (1);
  62.     glNewList(teapots[TEAPOTSOLID], GL_COMPILE);
  63.     glPushMatrix ();
  64.     glRotatef (270.0, 1.0, 0.0, 0.0);
  65.     glScalef (0.5*scale, 0.5*scale, 0.5*scale);
  66.     glTranslatef (0.0, 0.0, -1.5);
  67.     for (i = 0; i < 10; i++) {
  68.     for (j = 0; j < 4; j++)
  69.         for (k = 0; k < 4; k++) 
  70.         for (l = 0; l < 3; l++) {
  71.             p[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  72.             q[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  73.             if (l == 1) q[j][k][l] *= -1.0;
  74.             if (i < 6) {
  75.             r[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  76.             if (l == 0) r[j][k][l] *= -1.0;
  77.             s[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  78.             if (l == 0) s[j][k][l] *= -1.0;
  79.             if (l == 1) s[j][k][l] *= -1.0;
  80.             }
  81.         }
  82.     glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &tex[0][0][0]);
  83.     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &p[0][0][0]);
  84.     glEnable(GL_MAP2_VERTEX_3); glEnable(GL_MAP2_TEXTURE_COORD_2);
  85.     glMapGrid2f(GRD, 0.0, 1.0, GRD, 0.0, 1.0);
  86.     glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  87.     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &q[0][0][0]);
  88.     glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  89.     if (i < 6) {
  90.         glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &r[0][0][0]);
  91.         glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  92.         glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &s[0][0][0]);
  93.         glEvalMesh2(GL_FILL, 0, GRD, 0, GRD);
  94.     }
  95.     }
  96.     glDisable(GL_MAP2_VERTEX_3); glDisable(GL_MAP2_TEXTURE_COORD_2);
  97.     glPopMatrix ();
  98.     glEndList();
  99. }
  100.  
  101. static void wireTeapot(long grid, GLdouble scale)
  102. {
  103.     float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];
  104.     long i, j, k, l;
  105.     
  106.     if (grid < 2) grid = 7;
  107.     GRD = grid;
  108.     teapots[TEAPOTWIRE] = glGenLists (1);
  109.     glNewList(teapots[TEAPOTWIRE], GL_COMPILE);
  110.     glPushMatrix ();
  111.     glRotatef (270.0, 1.0, 0.0, 0.0);
  112.     glScalef (0.5*scale, 0.5*scale, 0.5*scale);
  113.     glTranslatef (0.0, 0.0, -1.5);
  114.     for (i = 0; i < 10; i++) {
  115.     for (j = 0; j < 4; j++)
  116.         for (k = 0; k < 4; k++) 
  117.         for (l = 0; l < 3; l++) {
  118.             p[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  119.             q[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  120.             if (l == 1) q[j][k][l] *= -1.0;
  121.             if (i < 6) {
  122.             r[j][k][l] = cpdata[patchdata[i][j*4+(3-k)]][l];
  123.             if (l == 0) r[j][k][l] *= -1.0;
  124.             s[j][k][l] = cpdata[patchdata[i][j*4+k]][l];
  125.             if (l == 0) s[j][k][l] *= -1.0;
  126.             if (l == 1) s[j][k][l] *= -1.0;
  127.             }
  128.         }
  129.     glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &tex[0][0][0]);
  130.     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &p[0][0][0]);
  131.     glEnable(GL_MAP2_VERTEX_3); glEnable(GL_MAP2_TEXTURE_COORD_2);
  132.     glMapGrid2f(GRD, 0.0, 1.0, GRD, 0.0, 1.0);
  133.     glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  134.     glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &q[0][0][0]);
  135.     glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  136.     if (i < 6) {
  137.         glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &r[0][0][0]);
  138.         glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  139.         glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &s[0][0][0]);
  140.         glEvalMesh2(GL_LINE, 0, GRD, 0, GRD);
  141.     }
  142.     }
  143.     glDisable(GL_MAP2_VERTEX_3); glDisable(GL_MAP2_TEXTURE_COORD_2);
  144.     glPopMatrix ();
  145.     glEndList();
  146. }
  147.  
  148. void auxSolidTeapot(GLdouble scale)
  149. {
  150.     if (glIsList(teapots[TEAPOTSOLID]) == 0)
  151.     solidTeapot (14, scale);
  152.     glCallList(teapots[TEAPOTSOLID]);
  153. }
  154.  
  155. void auxWireTeapot(GLdouble scale)
  156. {
  157.     if (glIsList(teapots[TEAPOTWIRE]) == 0)
  158.     wireTeapot (10, scale);
  159.     glCallList(teapots[TEAPOTWIRE]);
  160. }
  161.  
  162.