/************************************************************************ Notice: This (GPL) file is included when WIDGETS_95_BUILD_EXAMPLES is defined, otherwise there's no GPL code in this project. I added it to complete the conversion to OpenGL ES using the ANGLE project. The older/original GLUT evaluator method is still used with OpenGL. ************************************************************************/ #if XCV_GL #define XCV_HAVE_MiniGLUT_TEAPOT(...) glutSolidTeapot(__VA_ARGS__) //https://github.com/jtsiomb/miniglut/blob/master/miniglut.c /* MiniGLUT - minimal GLUT subset without dependencies Copyright (C) 2020 John Tsiombikas This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define NUM_TEAPOT_INDICES (sizeof teapot_index / sizeof *teapot_index) #define NUM_TEAPOT_VERTS (sizeof teapot_verts / sizeof *teapot_verts) #define NUM_TEAPOT_PATCHES (NUM_TEAPOT_INDICES / 16) //#define PATCH_SUBDIV 7 static char teapot_part_flip[] = { 1, 1, 1, 1, /* rim flip */ 1, 1, 1, 1, /* body1 flip */ 1, 1, 1, 1, /* body2 flip */ 1, 1, 1, 1, /* lid patch 1 flip */ 1, 1, 1, 1, /* lid patch 2 flip */ 1, -1, /* handle 1 flip */ 1, -1, /* handle 2 flip */ 1, -1, /* spout 1 flip */ 1, -1, /* spout 2 flip */ 1, 1, 1, 1 /* bottom flip */ }; static short teapot_part_rot[] = { 0, 90, 180, 270, /* rim rotations */ 0, 90, 180, 270, /* body patch 1 rotations */ 0, 90, 180, 270, /* body patch 2 rotations */ 0, 90, 180, 270, /* lid patch 1 rotations */ 0, 90, 180, 270, /* lid patch 2 rotations */ 0, 0, /* handle 1 rotations */ 0, 0, /* handle 2 rotations */ 0, 0, /* spout 1 rotations */ 0, 0, /* spout 2 rotations */ 0, 90, 180, 270 /* bottom rotations */ }; static char teapot_index[] = { /* rim */ 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* body1 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, /* body 2 */ 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* lid 1 */ 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3, 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3, 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3, 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3, /* lid 2 */ 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, /* handle 1 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, /* handle 2 */ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67, /* spout 1 */ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, /* spout 2 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, /* bottom */ 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37, 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37, 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37, 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37 }; static float teapot_verts[][3] = { { 0.2000f, 0.0000f, 2.70000f }, { 0.2000f, -0.1120f, 2.70000f }, { 0.1120f, -0.2000f, 2.70000f }, { 0.0000f, -0.2000f, 2.70000f }, { 1.3375f, 0.0000f, 2.53125f }, { 1.3375f, -0.7490f, 2.53125f }, { 0.7490f, -1.3375f, 2.53125f }, { 0.0000f, -1.3375f, 2.53125f }, { 1.4375f, 0.0000f, 2.53125f }, { 1.4375f, -0.8050f, 2.53125f }, { 0.8050f, -1.4375f, 2.53125f }, { 0.0000f, -1.4375f, 2.53125f }, { 1.5000f, 0.0000f, 2.40000f }, { 1.5000f, -0.8400f, 2.40000f }, { 0.8400f, -1.5000f, 2.40000f }, { 0.0000f, -1.5000f, 2.40000f }, { 1.7500f, 0.0000f, 1.87500f }, { 1.7500f, -0.9800f, 1.87500f }, { 0.9800f, -1.7500f, 1.87500f }, { 0.0000f, -1.7500f, 1.87500f }, { 2.0000f, 0.0000f, 1.35000f }, { 2.0000f, -1.1200f, 1.35000f }, { 1.1200f, -2.0000f, 1.35000f }, { 0.0000f, -2.0000f, 1.35000f }, { 2.0000f, 0.0000f, 0.90000f }, { 2.0000f, -1.1200f, 0.90000f }, { 1.1200f, -2.0000f, 0.90000f }, { 0.0000f, -2.0000f, 0.90000f }, { -2.0000f, 0.0000f, 0.90000f }, { 2.0000f, 0.0000f, 0.45000f }, { 2.0000f, -1.1200f, 0.45000f }, { 1.1200f, -2.0000f, 0.45000f }, { 0.0000f, -2.0000f, 0.45000f }, { 1.5000f, 0.0000f, 0.22500f }, { 1.5000f, -0.8400f, 0.22500f }, { 0.8400f, -1.5000f, 0.22500f }, { 0.0000f, -1.5000f, 0.22500f }, { 1.5000f, 0.0000f, 0.15000f }, { 1.5000f, -0.8400f, 0.15000f }, { 0.8400f, -1.5000f, 0.15000f }, { 0.0000f, -1.5000f, 0.15000f }, { -1.6000f, 0.0000f, 2.02500f }, { -1.6000f, -0.3000f, 2.02500f }, { -1.5000f, -0.3000f, 2.25000f }, { -1.5000f, 0.0000f, 2.25000f }, { -2.3000f, 0.0000f, 2.02500f }, { -2.3000f, -0.3000f, 2.02500f }, { -2.5000f, -0.3000f, 2.25000f }, { -2.5000f, 0.0000f, 2.25000f }, { -2.7000f, 0.0000f, 2.02500f }, { -2.7000f, -0.3000f, 2.02500f }, { -3.0000f, -0.3000f, 2.25000f }, { -3.0000f, 0.0000f, 2.25000f }, { -2.7000f, 0.0000f, 1.80000f }, { -2.7000f, -0.3000f, 1.80000f }, { -3.0000f, -0.3000f, 1.80000f }, { -3.0000f, 0.0000f, 1.80000f }, { -2.7000f, 0.0000f, 1.57500f }, { -2.7000f, -0.3000f, 1.57500f }, { -3.0000f, -0.3000f, 1.35000f }, { -3.0000f, 0.0000f, 1.35000f }, { -2.5000f, 0.0000f, 1.12500f }, { -2.5000f, -0.3000f, 1.12500f }, { -2.6500f, -0.3000f, 0.93750f }, { -2.6500f, 0.0000f, 0.93750f }, { -2.0000f, -0.3000f, 0.90000f }, { -1.9000f, -0.3000f, 0.60000f }, { -1.9000f, 0.0000f, 0.60000f }, { 1.7000f, 0.0000f, 1.42500f }, { 1.7000f, -0.6600f, 1.42500f }, { 1.7000f, -0.6600f, 0.60000f }, { 1.7000f, 0.0000f, 0.60000f }, { 2.6000f, 0.0000f, 1.42500f }, { 2.6000f, -0.6600f, 1.42500f }, { 3.1000f, -0.6600f, 0.82500f }, { 3.1000f, 0.0000f, 0.82500f }, { 2.3000f, 0.0000f, 2.10000f }, { 2.3000f, -0.2500f, 2.10000f }, { 2.4000f, -0.2500f, 2.02500f }, { 2.4000f, 0.0000f, 2.02500f }, { 2.7000f, 0.0000f, 2.40000f }, { 2.7000f, -0.2500f, 2.40000f }, { 3.3000f, -0.2500f, 2.40000f }, { 3.3000f, 0.0000f, 2.40000f }, { 2.8000f, 0.0000f, 2.47500f }, { 2.8000f, -0.2500f, 2.47500f }, { 3.5250f, -0.2500f, 2.49375f }, { 3.5250f, 0.0000f, 2.49375f }, { 2.9000f, 0.0000f, 2.47500f }, { 2.9000f, -0.1500f, 2.47500f }, { 3.4500f, -0.1500f, 2.51250f }, { 3.4500f, 0.0000f, 2.51250f }, { 2.8000f, 0.0000f, 2.40000f }, { 2.8000f, -0.1500f, 2.40000f }, { 3.2000f, -0.1500f, 2.40000f }, { 3.2000f, 0.0000f, 2.40000f }, { 0.0000f, 0.0000f, 3.15000f }, { 0.8000f, 0.0000f, 3.15000f }, { 0.8000f, -0.4500f, 3.15000f }, { 0.4500f, -0.8000f, 3.15000f }, { 0.0000f, -0.8000f, 3.15000f }, { 0.0000f, 0.0000f, 2.85000f }, { 1.4000f, 0.0000f, 2.40000f }, { 1.4000f, -0.7840f, 2.40000f }, { 0.7840f, -1.4000f, 2.40000f }, { 0.0000f, -1.4000f, 2.40000f }, { 0.4000f, 0.0000f, 2.55000f }, { 0.4000f, -0.2240f, 2.55000f }, { 0.2240f, -0.4000f, 2.55000f }, { 0.0000f, -0.4000f, 2.55000f }, { 1.3000f, 0.0000f, 2.55000f }, { 1.3000f, -0.7280f, 2.55000f }, { 0.7280f, -1.3000f, 2.55000f }, { 0.0000f, -1.3000f, 2.55000f }, { 1.3000f, 0.0000f, 2.40000f }, { 1.3000f, -0.7280f, 2.40000f }, { 0.7280f, -1.3000f, 2.40000f }, { 0.0000f, -1.3000f, 2.40000f }, { 0.0000f, 0.0000f, 0.00000f }, { 1.4250f, -0.7980f, 0.00000f }, { 1.5000f, 0.0000f, 0.07500f }, { 1.4250f, 0.0000f, 0.00000f }, { 0.7980f, -1.4250f, 0.00000f }, { 0.0000f, -1.5000f, 0.07500f }, { 0.0000f, -1.4250f, 0.00000f }, { 1.5000f, -0.8400f, 0.07500f }, { 0.8400f, -1.5000f, 0.07500f } }; static float bernstein(int i, float x) { float invx = 1.0f - x; switch(i) { case 0: return invx * invx * invx; case 1: return 3.0f * x * invx * invx; case 2: return 3.0f * x * x * invx; case 3: return x * x * x; default: break; } return 0.0f; } static void bezier_patch(float *res, float *cp, float u, float v) { int i, j; res[0] = res[1] = res[2] = 0.0f; for(j=0; j<4; j++) { for(i=0; i<4; i++) { float bu = bernstein(i, u); float bv = bernstein(j, v); res[0] += cp[0] * bu * bv; res[1] += cp[1] * bu * bv; res[2] += cp[2] * bu * bv; cp += 3; } } } static float rsqrt(float x) { float xhalf = x * 0.5f; int i = *(int*)&x; i = 0x5f3759df - (i >> 1); x = *(float*)&i; x = x * (1.5f - xhalf * x * x); return x; } #define CROSS(res, a, b) \ do { \ (res)[0] = (a)[1] * (b)[2] - (a)[2] * (b)[1]; \ (res)[1] = (a)[2] * (b)[0] - (a)[0] * (b)[2]; \ (res)[2] = (a)[0] * (b)[1] - (a)[1] * (b)[0]; \ } while(0) #define NORMALIZE(v) \ do { \ float s = rsqrt((v)[0] * (v)[0] + (v)[1] * (v)[1] + (v)[2] * (v)[2]); \ (v)[0] *= s; \ (v)[1] *= s; \ (v)[2] *= s; \ } while(0) #define DT 0.001 static void bezier_patch_norm(float *res, float *cp, float u, float v) { float tang[3], bitan[3], tmp[3]; bezier_patch(tang, cp, u + DT, v); bezier_patch(tmp, cp, u - DT, v); tang[0] -= tmp[0]; tang[1] -= tmp[1]; tang[2] -= tmp[2]; bezier_patch(bitan, cp, u, v + DT); bezier_patch(tmp, cp, u, v - DT); bitan[0] -= tmp[0]; bitan[1] -= tmp[1]; bitan[2] -= tmp[2]; CROSS(res, tang, bitan); NORMALIZE(res); } static void draw_patch(int PATCH_SUBDIV, char *index, int flip, float scale) { static const float uoffs[2][4] = {{0, 0, 1, 1}, {1, 1, 0, 0}}; static const float voffs[4] = {0, 1, 1, 0}; int i, j, k; float cp[16 * 3]; float pt[3], n[3]; float u, v; float du = 1.0f / PATCH_SUBDIV; float dv = 1.0f / PATCH_SUBDIV; /* collect control points */ for(i=0; i<16; i++) { cp[i * 3] = teapot_verts[index[i]][0]; cp[i * 3 + 1] = teapot_verts[index[i]][1]; cp[i * 3 + 2] = teapot_verts[index[i]][2]; } gl::glBegin(GL_QUADS); gl::glColor3f(1, 1, 1); u = 0; for(i=0; i 3.14) { n[0] = n[1] = 0.0f; n[2] = 1.0f; } else if(pt[2] < 0.00001) { n[0] = n[1] = 0.0f; n[2] = -1.0f; } else { bezier_patch_norm(n, cp, u + uoffs[flip][k] * du, v + voffs[k] * dv); } gl::glTexCoord2f(u, v); gl::glNormal3f(n[0],n[1],n[2]); gl::glVertex3f(pt[0] * scale, pt[1] * scale, pt[2] * scale); } v += dv; } u += du; } gl::glEnd(); } static void glutSolidTeapot(int PATCH_SUBDIV, float size) { int i; size /= 2.0; for(i=0; i> 1); s = gray & 1 ? u + du : u; t = gray & 2 ? v + dv : v; theta = s * (float)M_PI * 2.0f; phi = t * (float)M_PI; mglut_sincos(theta, &sintheta, &costheta); mglut_sincos(phi, &sinphi, &cosphi); x = sintheta * sinphi; y = costheta * sinphi; z = cosphi; // gl::glColor3f(s, t, 1); gl::glTexCoord2f(s, t); gl::glNormal3f(x, y, z); gl::glVertex3f(x * rad, y * rad, z * rad); } } } gl::glEnd(); } #endif //XCV_GL #ifdef __GL_H__ #define XCV_HAVE_GLUT_TEAPOT(...) teapot(__VA_ARGS__) //https://github.com/markkilgard/glut/tree/master/lib/glut/glut_teapot.c /* Copyright (c) Mark J. Kilgard, 1994, 2001. */ /** (c) Copyright 1993, Silicon Graphics, Inc. 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 the name of Silicon Graphics, Inc. not be used in advertising or publicity pertaining to distribution of the software without specific, 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, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 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 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 clause at DFARS 252.227-7013 and/or in similar or successor clauses in the FAR or the DOD or NASA FAR Supplement. Unpublished-- rights reserved under the copyright laws of the United States. Contractor/manufacturer is Silicon Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. OpenGL(TM) is a trademark of Silicon Graphics, Inc. */ //#include "glutint.h" /* Rim, body, lid, and bottom data must be reflected in x and y; handle and spout data across the y axis only. */ //static const int patchdata[][16] = static const unsigned char patchdata[][16] = { /* rim */ {102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, /* body */ {12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27}, {24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40}, /* lid */ {96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3,}, {0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117}, /* bottom */ {118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37}, /* handle */ {41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56}, {53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67}, /* spout */ {68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83}, {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95} }; /* *INDENT-OFF* */ static const float cpdata[][3] = { {0.2f, 0.0f, 2.7f}, {0.2f, -0.112f, 2.7f}, {0.112f, -0.2f, 2.7f}, {0.0f, -0.2f, 2.7f}, {1.3375f, 0.0f, 2.53125f}, {1.3375f, -0.749f, 2.53125f}, {0.749f, -1.3375f, 2.53125f}, {0.0f, -1.3375f, 2.53125f}, {1.4375f, 0.0f, 2.53125f}, {1.4375f, -0.805f, 2.53125f}, {0.805f, -1.4375f, 2.53125f}, {0.0f, -1.4375f, 2.53125f}, {1.5f, 0.0f, 2.4f}, {1.5f, -0.84f, 2.4f}, {0.84f, -1.5f, 2.4f}, {0.0f, -1.5f, 2.4f}, {1.75f, 0.0f, 1.875f}, {1.75f, -0.98f, 1.875f}, {0.98f, -1.75f, 1.875f}, {0.0f, -1.75f, 1.875f}, {2.0f, 0.0f, 1.35f}, {2.0f, -1.12f, 1.35f}, {1.12f, -2.0f, 1.35f}, {0.0f, -2.0f, 1.35f}, {2.0f, 0.0f, 0.9f}, {2.0f, -1.12f, 0.9f}, {1.12f, -2.0f, 0.9f}, {0.0f, -2.0f, 0.9f}, {-2.0f, 0.0f, 0.9f}, {2.0f, 0.0f, 0.45f}, {2.0f, -1.12f, 0.45f}, {1.12f, -2.0f, 0.45f}, {0.0f, -2.0f, 0.45f}, {1.5f, 0.0f, 0.225f}, {1.5f, -0.84f, 0.225f}, {0.84f, -1.5f, 0.225f}, {0.0f, -1.5f, 0.225f}, {1.5f, 0.0f, 0.15f}, {1.5f, -0.84f, 0.15f}, {0.84f, -1.5f, 0.15f}, {0.0f, -1.5f, 0.15f}, {-1.6f, 0.0f, 2.025f}, {-1.6f, -0.3f, 2.025f}, {-1.5f, -0.3f, 2.25f}, {-1.5f, 0.0f, 2.25f}, {-2.3f, 0.0f, 2.025f}, {-2.3f, -0.3f, 2.025f}, {-2.5f, -0.3f, 2.25f}, {-2.5f, 0.0f, 2.25f}, {-2.7f, 0.0f, 2.025f}, {-2.7f, -0.3f, 2.025f}, {-3.0f, -0.3f, 2.25f}, {-3.0f, 0.0f, 2.25f}, {-2.7f, 0.0f, 1.8f}, {-2.7f, -0.3f, 1.8f}, {-3.0f, -0.3f, 1.8f}, {-3.0f, 0.0f, 1.8f}, {-2.7f, 0.0f, 1.575f}, {-2.7f, -0.3f, 1.575f}, {-3.0f, -0.3f, 1.35f}, {-3.0f, 0.0f, 1.35f}, {-2.5f, 0.0f, 1.125f}, {-2.5f, -0.3f, 1.125f}, {-2.65f, -0.3f, 0.9375f}, {-2.65f, 0.0f, 0.9375f}, {-2.0f, -0.3f, 0.9f}, {-1.9f, -0.3f, 0.6f}, {-1.9f, 0.0f, 0.6f}, {1.7f, 0.0f, 1.425f}, {1.7f, -0.66f, 1.425f}, {1.7f, -0.66f, 0.6f}, {1.7f, 0.0f, 0.6f}, {2.6f, 0.0f, 1.425f}, {2.6f, -0.66f, 1.425f}, {3.1f, -0.66f, 0.825f}, {3.1f, 0.0f, 0.825f}, {2.3f, 0.0f, 2.1f}, {2.3f, -0.25f, 2.1f}, {2.4f, -0.25f, 2.025f}, {2.4f, 0.0f, 2.025f}, {2.7f, 0.0f, 2.4f}, {2.7f, -0.25f, 2.4f}, {3.3f, -0.25f, 2.4f}, {3.3f, 0.0f, 2.4f}, {2.8f, 0.0f, 2.475f}, {2.8f, -0.25f, 2.475f}, {3.525f, -0.25f, 2.49375f}, {3.525f, 0.0f, 2.49375f}, {2.9f, 0.0f, 2.475f}, {2.9f, -0.15f, 2.475f}, {3.45f, -0.15f, 2.5125f}, {3.45f, 0.0f, 2.5125f}, {2.8f, 0.0f, 2.4f}, {2.8f, -0.15f, 2.4f}, {3.2f, -0.15f, 2.4f}, {3.2f, 0.0f, 2.4f}, {0.0f, 0.0f, 3.15f}, {0.8f, 0.0f, 3.15f}, {0.8f, -0.45f, 3.15f}, {0.45f, -0.8f, 3.15f}, {0.0f, -0.8f, 3.15f}, {0.0f, 0.0f, 2.85f}, {1.4f, 0.0f, 2.4f}, {1.4f, -0.784f, 2.4f}, {0.784f, -1.4f, 2.4f}, {0.0f, -1.4f, 2.4f}, {0.4f, 0.0f, 2.55f}, {0.4f, -0.224f, 2.55f}, {0.224f, -0.4f, 2.55f}, {0.0f, -0.4f, 2.55f}, {1.3f, 0.0f, 2.55f}, {1.3f, -0.728f, 2.55f}, {0.728f, -1.3f, 2.55f}, {0.0f, -1.3f, 2.55f}, {1.3f, 0.0f, 2.4f}, {1.3f, -0.728f, 2.4f}, {0.728f, -1.3f, 2.4f}, {0.0f, -1.3f, 2.4f}, {0.0f, 0.0f, 0.0f}, {1.425f, -0.798f, 0.0f}, {1.5f, 0.0f, 0.075f}, {1.425f, 0.0f, 0.0f}, {0.798f, -1.425f, 0.0f}, {0.0f, -1.5f, 0.075f}, {0.0f, -1.425f, 0.0f}, {1.5f, -0.84f, 0.075f}, {0.84f, -1.5f, 0.075f} }; static const float tex[2][2][2] = { { {0, 0}, {1, 0}}, { {0, 1}, {1, 1}} }; /* *INDENT-ON* */ static void teapot(GLint grid, GLdouble scale, GLenum type) { float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3]; long i, j, k, l; ::glPushAttrib(GL_ENABLE_BIT | GL_EVAL_BIT); ::glEnable(GL_AUTO_NORMAL); ::glEnable(GL_NORMALIZE); ::glEnable(GL_MAP2_VERTEX_3); ::glEnable(GL_MAP2_TEXTURE_COORD_2); ::glPushMatrix(); ::glRotatef(270.0, 1.0, 0.0, 0.0); ::glScalef(0.5 * scale, 0.5 * scale, 0.5 * scale); ::glTranslatef(0.0, 0.0, -1.5); for (i = 0; i < 10; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { for (l = 0; l < 3; l++) { p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]; if (l == 1) { q[j][k][l] *= -1.0; } if (i < 6) { r[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]; if (l == 0) { r[j][k][l] *= -1.0; } s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; if (l == 0) { s[j][k][l] *= -1.0; } if (l == 1) { s[j][k][l] *= -1.0; } } } } } ::glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &tex[0][0][0]); ::glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &p[0][0][0]); ::glMapGrid2f(grid, 0.0, 1.0, grid, 0.0, 1.0); ::glEvalMesh2(type, 0, grid, 0, grid); ::glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &q[0][0][0]); ::glEvalMesh2(type, 0, grid, 0, grid); if (i < 6) { ::glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &r[0][0][0]); ::glEvalMesh2(type, 0, grid, 0, grid); ::glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &s[0][0][0]); ::glEvalMesh2(type, 0, grid, 0, grid); } } ::glPopMatrix(); ::glPopAttrib(); } #endif //__GL_H__