~ubuntu-branches/ubuntu/precise/xscreensaver/precise

« back to all changes in this revision

Viewing changes to hacks/glx/tube.c

  • Committer: Bazaar Package Importer
  • Author(s): Tormod Volden
  • Date: 2011-04-22 23:07:13 UTC
  • mfrom: (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 41.
  • Revision ID: james.westby@ubuntu.com-20110422230713-wcixfinu45mm7vsx
Tags: 5.13-1
* New upstream version 5.13
  - Passwords that contain UTF-8 non-Latin1 chars are now typeable
  - pt_BR translation (thanks Sérgio Cipolla!) (Closes: #586230)
  - Fix memory leak in gltext (LP: #768032)
* Build without gdm and libgnome2-dev (Closes: #618165)
* Add Suggests on gdm3 or kdm-gdmcompat because gdmflexiserver
  can be used for the "New Login" functionality (see bug #304406)
* Remove obsolete gdmflexiserver options
* xscreensaver.desktop changes:
  - Do not set StartupNotify.
  - Do not specify svg icon. Closes: #618723 (LP: #603222)
* Fix installation path for xscreensaver-daemon.desktop 
* debian/xscreensaver.preinst: Check version before
  deleting obsolete configuration files (Closes: #588288)
* Bump Standards-Version to 3.9.2 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* tube, Copyright (c) 2001, 2003, 2007 Jamie Zawinski <jwz@jwz.org>
 
1
/* tube, Copyright (c) 2001-2011 Jamie Zawinski <jwz@jwz.org>
2
2
 * Utility functions to create tubes and cones in GL.
3
3
 *
4
4
 * Permission to use, copy, modify, distribute, and sell this software and its
26
26
 
27
27
#include "tube.h"
28
28
 
 
29
typedef struct { GLfloat x, y, z; } XYZ;
 
30
 
 
31
 
29
32
static int
30
33
unit_tube (int faces, int smooth, int caps_p, int wire_p)
31
34
{
37
40
  GLfloat x, y, x0=0, y0=0;
38
41
  int z = 0;
39
42
 
 
43
  int arraysize, out;
 
44
  struct { XYZ p; XYZ n; GLfloat s, t; } *array;
 
45
 
 
46
  arraysize = (faces+1) * 6;
 
47
  array = (void *) calloc (arraysize, sizeof(*array));
 
48
  if (! array) abort();
 
49
  out = 0;
 
50
 
 
51
 
 
52
  /* #### texture coords are currently not being computed */
 
53
 
 
54
 
40
55
  /* side walls
41
56
   */
42
 
  glFrontFace(GL_CCW);
43
 
  glBegin (wire_p ? GL_LINES : (smooth ? GL_QUAD_STRIP : GL_QUADS));
44
 
 
45
57
  th = 0;
46
58
  x = 1;
47
59
  y = 0;
56
68
 
57
69
  for (i = 0; i < faces; i++)
58
70
    {
 
71
      array[out].p.x = x;                       /* bottom point A */
 
72
      array[out].p.y = 0;
 
73
      array[out].p.z = y;
 
74
 
59
75
      if (smooth)
60
 
        glNormal3f(x, 0, y);
 
76
        array[out].n = array[out].p;            /* its own normal */
61
77
      else
62
 
        glNormal3f(x0, 0, y0);
63
 
 
64
 
      glVertex3f(x, 0, y);
65
 
      glVertex3f(x, 1, y);
 
78
        {
 
79
          array[out].n.x = x0;                  /* mid-plane normal */
 
80
          array[out].n.y = 0;
 
81
          array[out].n.z = y0;
 
82
        }
 
83
      out++;
 
84
 
 
85
 
 
86
      array[out].p.x = x;                       /* top point A */
 
87
      array[out].p.y = 1;
 
88
      array[out].p.z = y;
 
89
      array[out].n = array[out-1].n;            /* same normal */
 
90
      out++;
 
91
 
66
92
 
67
93
      th += step;
68
94
      x  = cos (th);
73
99
          x0 = cos (th + s2);
74
100
          y0 = sin (th + s2);
75
101
 
76
 
          glVertex3f(x, 1, y);
77
 
          glVertex3f(x, 0, y);
 
102
          array[out].p.x = x;                   /* top point B */
 
103
          array[out].p.y = 1;
 
104
          array[out].p.z = y;
 
105
          array[out].n = array[out-1].n;        /* same normal */
 
106
          out++;
 
107
 
 
108
 
 
109
          array[out] = array[out-3];            /* bottom point A */
 
110
          out++;
 
111
 
 
112
          array[out] = array[out-2];            /* top point B */
 
113
          out++;
 
114
 
 
115
          array[out].p.x = x;                   /* bottom point B */
 
116
          array[out].p.y = 0;
 
117
          array[out].p.z = y;
 
118
          array[out].n = array[out-1].n;        /* same normal */
 
119
          out++;
 
120
 
 
121
          polys++;
78
122
        }
 
123
 
79
124
      polys++;
 
125
      if (out >= arraysize) abort();
80
126
    }
81
 
  glEnd();
 
127
 
 
128
  glEnableClientState (GL_VERTEX_ARRAY);
 
129
  glEnableClientState (GL_NORMAL_ARRAY);
 
130
  glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
131
 
 
132
  glVertexPointer   (3, GL_FLOAT, sizeof(*array), &array[0].p);
 
133
  glNormalPointer   (   GL_FLOAT, sizeof(*array), &array[0].n);
 
134
  glTexCoordPointer (2, GL_FLOAT, sizeof(*array), &array[0].s);
 
135
 
 
136
  glDrawArrays ((wire_p ? GL_LINES :
 
137
                 (smooth ? GL_TRIANGLE_STRIP : GL_TRIANGLES)),
 
138
                0, out);
 
139
 
82
140
 
83
141
  /* End caps
84
142
   */
85
143
  if (caps_p)
86
144
    for (z = 0; z <= 1; z++)
87
145
      {
88
 
        glFrontFace(z == 0 ? GL_CCW : GL_CW);
89
 
        glNormal3f(0, (z == 0 ? -1 : 1), 0);
90
 
        glBegin(wire_p ? GL_LINE_LOOP : GL_TRIANGLE_FAN);
91
 
        if (! wire_p) glVertex3f(0, z, 0);
92
 
        for (i = 0, th = 0; i <= faces; i++)
 
146
        out = 0;
 
147
        if (! wire_p)
93
148
          {
 
149
            array[out].p.x = 0;
 
150
            array[out].p.y = z;
 
151
            array[out].p.z = 0;
 
152
 
 
153
            array[out].n.x = 0;
 
154
            array[out].n.y = (z == 0 ? -1 : 1);
 
155
            array[out].n.z = 0;
 
156
            out++;
 
157
          }
 
158
 
 
159
        th = 0;
 
160
        for (i = (z == 0 ? 0 : faces);
 
161
             (z == 0 ? i <= faces : i >= 0);
 
162
             i += (z == 0 ? 1 : -1)) {
94
163
            GLfloat x = cos (th);
95
164
            GLfloat y = sin (th);
96
 
            glVertex3f(x, z, y);
97
 
            th += step;
 
165
 
 
166
            array[out] = array[0];  /* same normal and texture */
 
167
            array[out].p.x = x;
 
168
            array[out].p.y = z;
 
169
            array[out].p.z = y;
 
170
            out++;
 
171
 
 
172
            th += (z == 0 ? step : -step);
 
173
 
98
174
            polys++;
 
175
            if (out >= arraysize) abort();
99
176
          }
100
 
        glEnd();
 
177
 
 
178
        glVertexPointer   (3, GL_FLOAT, sizeof(*array), &array[0].p);
 
179
        glNormalPointer   (   GL_FLOAT, sizeof(*array), &array[0].n);
 
180
        glTexCoordPointer (2, GL_FLOAT, sizeof(*array), &array[0].s);
 
181
 
 
182
        glDrawArrays ((wire_p ? GL_LINE_LOOP : GL_TRIANGLE_FAN), 0, out);
101
183
      }
 
184
 
 
185
  free(array);
 
186
 
102
187
  return polys;
103
188
}
104
189
 
113
198
  GLfloat th;
114
199
  GLfloat x, y, x0, y0;
115
200
 
 
201
  int arraysize, out;
 
202
  struct { XYZ p; XYZ n; GLfloat s, t; } *array;
 
203
 
 
204
  arraysize = (faces+1) * 3;
 
205
  array = (void *) calloc (arraysize, sizeof(*array));
 
206
  if (! array) abort();
 
207
  out = 0;
 
208
 
 
209
 
 
210
  /* #### texture coords are currently not being computed */
 
211
 
 
212
 
116
213
  /* side walls
117
214
   */
118
 
  glFrontFace(GL_CW);
119
 
  glBegin(wire_p ? GL_LINES : GL_TRIANGLES);
120
215
 
121
216
  th = 0;
122
217
  x = 1;
126
221
 
127
222
  for (i = 0; i < faces; i++)
128
223
    {
129
 
      glNormal3f(x0, 0, y0);
130
 
      glVertex3f(0,  1, 0);
131
 
 
132
 
      if (smooth) glNormal3f(x, 0, y);
133
 
      glVertex3f(x, 0, y);
 
224
      array[out].p.x = x;               /* bottom point A */
 
225
      array[out].p.y = 0;
 
226
      array[out].p.z = y;
 
227
 
 
228
      if (smooth)
 
229
        array[out].n = array[out].p;    /* its own normal */
 
230
      else
 
231
        {
 
232
          array[out].n.x = x0;          /* mid-plane normal */
 
233
          array[out].n.y = 0;
 
234
          array[out].n.z = y0;
 
235
        }
 
236
      out++;
 
237
 
 
238
 
 
239
      array[out].p.x = 0;               /* tip point */
 
240
      array[out].p.y = 1;
 
241
      array[out].p.z = 0;
 
242
 
 
243
      array[out].n.x = x0;              /* mid-plane normal */
 
244
      array[out].n.y = 0;
 
245
      array[out].n.z = y0;
 
246
      out++;
 
247
 
134
248
 
135
249
      th += step;
136
250
      x0 = cos (th + s2);
138
252
      x  = cos (th);
139
253
      y  = sin (th);
140
254
 
141
 
      if (smooth) glNormal3f(x, 0, y);
142
 
      glVertex3f(x, 0, y);
 
255
      array[out].p.x = x;               /* bottom point B */
 
256
      array[out].p.y = 0;
 
257
      array[out].p.z = y;
 
258
 
 
259
      if (smooth)
 
260
        array[out].n = array[out].p;    /* its own normal */
 
261
      else
 
262
        array[out].n = array[out-1].n;  /* same normal as other two */
 
263
      out++;
 
264
 
 
265
 
 
266
      if (out >= arraysize) abort();
143
267
      polys++;
144
268
    }
145
 
  glEnd();
 
269
 
 
270
  glEnableClientState (GL_VERTEX_ARRAY);
 
271
  glEnableClientState (GL_NORMAL_ARRAY);
 
272
  glEnableClientState (GL_TEXTURE_COORD_ARRAY);
 
273
 
 
274
  glVertexPointer   (3, GL_FLOAT, sizeof(*array), &array[0].p);
 
275
  glNormalPointer   (   GL_FLOAT, sizeof(*array), &array[0].n);
 
276
  glTexCoordPointer (2, GL_FLOAT, sizeof(*array), &array[0].s);
 
277
 
 
278
  glDrawArrays ((wire_p ? GL_LINES : GL_TRIANGLES), 0, out);
 
279
 
146
280
 
147
281
  /* End cap
148
282
   */
149
283
  if (cap_p)
150
284
    {
151
 
      glFrontFace(GL_CCW);
152
 
      glNormal3f(0, -1, 0);
153
 
      glBegin(wire_p ? GL_LINE_LOOP : GL_TRIANGLE_FAN);
154
 
      if (! wire_p) glVertex3f(0, 0, 0);
 
285
      out = 0;
 
286
 
 
287
      if (! wire_p)
 
288
        {
 
289
          array[out].p.x = 0;
 
290
          array[out].p.y = 0;
 
291
          array[out].p.z = 0;
 
292
 
 
293
          array[out].n.x = 0;
 
294
          array[out].n.y = -1;
 
295
          array[out].n.z = 0;
 
296
          out++;
 
297
        }
 
298
 
155
299
      for (i = 0, th = 0; i <= faces; i++)
156
300
        {
157
301
          GLfloat x = cos (th);
158
302
          GLfloat y = sin (th);
159
 
          glVertex3f(x, 0, y);
 
303
 
 
304
          array[out] = array[0];  /* same normal and texture */
 
305
          array[out].p.x = x;
 
306
          array[out].p.y = 0;
 
307
          array[out].p.z = y;
 
308
          out++;
160
309
          th += step;
161
310
          polys++;
 
311
          if (out >= arraysize) abort();
162
312
        }
163
 
      glEnd();
 
313
 
 
314
      glVertexPointer   (3, GL_FLOAT, sizeof(*array), &array[0].p);
 
315
      glNormalPointer   (   GL_FLOAT, sizeof(*array), &array[0].n);
 
316
      glTexCoordPointer (2, GL_FLOAT, sizeof(*array), &array[0].s);
 
317
 
 
318
      glDrawArrays ((wire_p ? GL_LINE_LOOP : GL_TRIANGLE_FAN), 0, out);
164
319
    }
 
320
 
 
321
  free (array);
 
322
 
165
323
  return polys;
166
324
}
167
325