http://packetstorm.tacticalflex.com/UNIX/admin/xscreensaver-3.27.tar.gz
[xscreensaver] / hacks / glx / buildlwo.c
1
2 #if !defined( lint ) && !defined( SABER )
3 static const char sccsid[] = "@(#)buildlwo.c    4.02 97/04/20 xlockmore";
4
5 #endif
6
7 /*-
8  * buildlwo.c: Lightwave Object Display List Builder for OpenGL
9  *
10  * This module can be called by any GL mode wishing to use
11  * objects created in NewTek's Lightwave 3D.  The objects must
12  * first be converted to C source with my converter "lw2ogl".
13  * If other people are interested in this, I will put up a
14  * web page for it at http://www.netaxs.com/~emackey/lw2ogl/
15  *
16  * by Ed Mackey, 4/19/97
17  *
18  */
19
20 #ifndef STANDALONE
21 #include "xlock.h"
22 #endif
23
24 #ifdef USE_GL
25
26 #ifdef STANDALONE
27 #include <GL/glx.h>
28 #endif
29 #include <GL/gl.h>
30 #include <GL/glu.h>
31 #include "buildlwo.h"
32
33 GLuint
34 BuildLWO(int wireframe, struct lwo *object)
35 {
36         GLuint      dl_num;
37         GLfloat    *pnts, *normals, three[3], *grab;
38         unsigned short int *pols;
39         int         p, num_pnts = 0;
40
41         dl_num = glGenLists(1);
42         if (!dl_num)
43                 return (0);
44
45         pnts = object->pnts;
46         normals = object->normals;
47         pols = object->pols;
48
49         glNewList(dl_num, GL_COMPILE);
50
51         if (!pols) {
52                 num_pnts = object->num_pnts;
53                 glBegin(GL_POINTS);
54                 for (p = 0; p < num_pnts; ++p) {
55                         three[0] = *(pnts++);
56                         three[1] = *(pnts++);
57                         three[2] = *(pnts++);
58                         glVertex3fv(three);
59                 }
60                 glEnd();
61         } else
62                 for (;;) {
63                         if (num_pnts <= 0) {
64                                 num_pnts = *pols + 2;
65                                 if (num_pnts < 3)
66                                         break;
67                                 if (num_pnts == 3) {
68                                         glBegin(GL_POINTS);
69                                 } else if (num_pnts == 4) {
70                                         glBegin(GL_LINES);
71                                 } else {
72                                         three[0] = *(normals++);
73                                         three[1] = *(normals++);
74                                         three[2] = *(normals++);
75                                         glNormal3fv(three);
76                                         if (wireframe)
77                                                 glBegin(GL_LINE_LOOP);
78                                         else
79                                                 glBegin(GL_POLYGON);
80                                 }
81                         } else if (num_pnts == 1) {
82                                 glEnd();
83                         } else {
84                                 grab = pnts + ((int) (*pols) * 3);
85                                 three[0] = *(grab++);
86                                 three[1] = *(grab++);
87                                 three[2] = *(grab++);
88                                 glVertex3fv(three);
89                         }
90                         --num_pnts;
91                         ++pols;
92                 }
93
94         glEndList();
95
96         return (dl_num);
97 }
98
99 #endif /* USE_GL */
100
101 /* End of buildlwo.c */