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