~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/box2d/freeglut/freeglut_teapot.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

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