http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.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 #ifdef STANDALONE
26 #include <GL/glx.h>
27 #endif
28 #include <GL/gl.h>
29 #include <GL/glu.h>
30 #include "buildlwo.h"
31
32 GLuint
33 BuildLWO(int wireframe, struct lwo *object)
34 {
35         GLuint      dl_num;
36         GLfloat    *pnts, *normals, three[3], *grab;
37         unsigned short int *pols;
38         int         p, num_pnts = 0;
39
40         dl_num = glGenLists(1);
41         if (!dl_num)
42                 return (0);
43
44         pnts = object->pnts;
45         normals = object->normals;
46         pols = object->pols;
47
48         glNewList(dl_num, GL_COMPILE);
49
50         if (!pols) {
51                 num_pnts = object->num_pnts;
52                 glBegin(GL_POINTS);
53                 for (p = 0; p < num_pnts; ++p) {
54                         three[0] = *(pnts++);
55                         three[1] = *(pnts++);
56                         three[2] = *(pnts++);
57                         glVertex3fv(three);
58                 }
59                 glEnd();
60         } else
61                 for (;;) {
62                         if (num_pnts <= 0) {
63                                 num_pnts = *pols + 2;
64                                 if (num_pnts < 3)
65                                         break;
66                                 if (num_pnts == 3) {
67                                         glBegin(GL_POINTS);
68                                 } else if (num_pnts == 4) {
69                                         glBegin(GL_LINES);
70                                 } else {
71                                         three[0] = *(normals++);
72                                         three[1] = *(normals++);
73                                         three[2] = *(normals++);
74                                         glNormal3fv(three);
75                                         if (wireframe)
76                                                 glBegin(GL_LINE_LOOP);
77                                         else
78                                                 glBegin(GL_POLYGON);
79                                 }
80                         } else if (num_pnts == 1) {
81                                 glEnd();
82                         } else {
83                                 grab = pnts + ((int) (*pols) * 3);
84                                 three[0] = *(grab++);
85                                 three[1] = *(grab++);
86                                 three[2] = *(grab++);
87                                 glVertex3fv(three);
88                         }
89                         --num_pnts;
90                         ++pols;
91                 }
92
93         glEndList();
94
95         return (dl_num);
96 }
97
98 #endif /* USE_GL */
99
100 /* End of buildlwo.c */