Splitting the X11-specific "freeglut_spaceball.c" code into its own file
[freeglut] / src / Common / freeglut_teapot.c
1 /*\r
2  * freeglut_teapot.c\r
3  *\r
4  * Teapot(tm) rendering code.\r
5  *\r
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.\r
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>\r
8  * Creation date: Fri Dec 24 1999\r
9  *\r
10  * Permission is hereby granted, free of charge, to any person obtaining a\r
11  * copy of this software and associated documentation files (the "Software"),\r
12  * to deal in the Software without restriction, including without limitation\r
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
14  * and/or sell copies of the Software, and to permit persons to whom the\r
15  * Software is furnished to do so, subject to the following conditions:\r
16  *\r
17  * The above copyright notice and this permission notice shall be included\r
18  * in all copies or substantial portions of the Software.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL\r
23  * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
24  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
25  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
26  */\r
27 \r
28 /*\r
29  * Original teapot code copyright follows:\r
30  */\r
31 \r
32 /*\r
33  * (c) Copyright 1993, Silicon Graphics, Inc.\r
34  *\r
35  * ALL RIGHTS RESERVED\r
36  *\r
37  * Permission to use, copy, modify, and distribute this software\r
38  * for any purpose and without fee is hereby granted, provided\r
39  * that the above copyright notice appear in all copies and that\r
40  * both the copyright notice and this permission notice appear in\r
41  * supporting documentation, and that the name of Silicon\r
42  * Graphics, Inc. not be used in advertising or publicity\r
43  * pertaining to distribution of the software without specific,\r
44  * written prior permission.\r
45  *\r
46  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU\r
47  * "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR\r
48  * OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF\r
49  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  IN NO\r
50  * EVENT SHALL SILICON GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE\r
51  * ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR\r
52  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER,\r
53  * INCLUDING WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE,\r
54  * SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD PARTIES, WHETHER OR\r
55  * NOT SILICON GRAPHICS, INC.  HAS BEEN ADVISED OF THE POSSIBILITY\r
56  * OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
57  * ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE OR\r
58  * PERFORMANCE OF THIS SOFTWARE.\r
59  *\r
60  * US Government Users Restricted Rights\r
61  *\r
62  * Use, duplication, or disclosure by the Government is subject to\r
63  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph\r
64  * (c)(1)(ii) of the Rights in Technical Data and Computer\r
65  * Software clause at DFARS 252.227-7013 and/or in similar or\r
66  * successor clauses in the FAR or the DOD or NASA FAR\r
67  * Supplement.  Unpublished-- rights reserved under the copyright\r
68  * laws of the United States.  Contractor/manufacturer is Silicon\r
69  * Graphics, Inc., 2011 N.  Shoreline Blvd., Mountain View, CA\r
70  * 94039-7311.\r
71  *\r
72  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.\r
73  */\r
74 \r
75 #include <GL/freeglut.h>\r
76 #include "freeglut_internal.h"\r
77 #include "freeglut_teapot_data.h"\r
78 \r
79 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */\r
80 \r
81 \r
82 static void fghTeapot( GLint grid, GLdouble scale, GLenum type )\r
83 {\r
84 #if defined(_WIN32_WCE)\r
85                 int i, numV=sizeof(strip_vertices)/4, numI=sizeof(strip_normals)/4;\r
86 #else\r
87     double p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3];\r
88     long i, j, k, l;\r
89 #endif\r
90 \r
91     glPushAttrib( GL_ENABLE_BIT | GL_EVAL_BIT );\r
92     glEnable( GL_AUTO_NORMAL );\r
93     glEnable( GL_NORMALIZE );\r
94     glEnable( GL_MAP2_VERTEX_3 );\r
95     glEnable( GL_MAP2_TEXTURE_COORD_2 );\r
96 \r
97     glPushMatrix();\r
98     glRotated( 270.0, 1.0, 0.0, 0.0 );\r
99     glScaled( 0.5 * scale, 0.5 * scale, 0.5 * scale );\r
100     glTranslated( 0.0, 0.0, -1.5 );\r
101 \r
102 #if defined(_WIN32_WCE)\r
103     glRotated( 90.0, 1.0, 0.0, 0.0 );\r
104     glBegin( GL_TRIANGLE_STRIP );\r
105 \r
106     for( i = 0; i < numV-1; i++ )\r
107     {\r
108         int vidx = strip_vertices[i],\r
109             nidx = strip_normals[i];\r
110 \r
111         if( vidx != -1 )\r
112         {\r
113             glNormal3fv( normals[nidx]  );\r
114             glVertex3fv( vertices[vidx] );\r
115         }\r
116         else\r
117         {\r
118             glEnd();\r
119             glBegin( GL_TRIANGLE_STRIP );\r
120         }\r
121     }\r
122 \r
123     glEnd();\r
124 #else\r
125     for (i = 0; i < 10; i++) {\r
126       for (j = 0; j < 4; j++) {\r
127         for (k = 0; k < 4; k++) {\r
128           for (l = 0; l < 3; l++) {\r
129             p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];\r
130             q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l];\r
131             if (l == 1)\r
132               q[j][k][l] *= -1.0;\r
133             if (i < 6) {\r
134               r[j][k][l] =\r
135                 cpdata[patchdata[i][j * 4 + (3 - k)]][l];\r
136               if (l == 0)\r
137                 r[j][k][l] *= -1.0;\r
138               s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l];\r
139               if (l == 0)\r
140                 s[j][k][l] *= -1.0;\r
141               if (l == 1)\r
142                 s[j][k][l] *= -1.0;\r
143             }\r
144           }\r
145         }\r
146       }\r
147 \r
148       glMap2d(GL_MAP2_TEXTURE_COORD_2, 0.0, 1.0, 2, 2, 0.0, 1.0, 4, 2,\r
149         &tex[0][0][0]);\r
150       glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,\r
151         &p[0][0][0]);\r
152       glMapGrid2d(grid, 0.0, 1.0, grid, 0.0, 1.0);\r
153       glEvalMesh2(type, 0, grid, 0, grid);\r
154       glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,\r
155         &q[0][0][0]);\r
156       glEvalMesh2(type, 0, grid, 0, grid);\r
157       if (i < 6) {\r
158         glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,\r
159           &r[0][0][0]);\r
160         glEvalMesh2(type, 0, grid, 0, grid);\r
161         glMap2d(GL_MAP2_VERTEX_3, 0.0, 1.0, 3, 4, 0.0, 1.0, 12, 4,\r
162           &s[0][0][0]);\r
163         glEvalMesh2(type, 0, grid, 0, grid);\r
164       }\r
165     }\r
166 #endif  /* defined(_WIN32_WCE) */\r
167 \r
168     glPopMatrix();\r
169     glPopAttrib();\r
170 }\r
171 \r
172 \r
173 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
174 \r
175 /*\r
176  * Renders a beautiful wired teapot...\r
177  */\r
178 void FGAPIENTRY glutWireTeapot( GLdouble size )\r
179 {\r
180     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutWireTeapot" );\r
181     /* We will use the general teapot rendering code */\r
182     fghTeapot( 10, size, GL_LINE );\r
183 }\r
184 \r
185 /*\r
186  * Renders a beautiful filled teapot...\r
187  */\r
188 void FGAPIENTRY glutSolidTeapot( GLdouble size )\r
189 {\r
190     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSolidTeapot" );\r
191     /* We will use the general teapot rendering code */\r
192     fghTeapot( 7, size, GL_FILL );\r
193 }\r
194 \r
195 /*** END OF FILE ***/\r
196 \r
197 \r
198 \r
199 \r
200 \r