]> git.xonotic.org Git - voretournament/voretournament.git/blob - misc/mediasource/netradiant-src/tools/quake2/q2map/glfile.c
Move all other sources in a separate subfolder
[voretournament/voretournament.git] / misc / mediasource / netradiant-src / tools / quake2 / q2map / glfile.c
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 #include "qbsp.h"
23
24 int             c_glfaces;
25
26 int PortalVisibleSides (portal_t *p)
27 {
28         int             fcon, bcon;
29
30         if (!p->onnode)
31                 return 0;               // outside
32
33         fcon = p->nodes[0]->contents;
34         bcon = p->nodes[1]->contents;
35
36         // same contents never create a face
37         if (fcon == bcon)
38                 return 0;
39
40         // FIXME: is this correct now?
41         if (!fcon)
42                 return 1;
43         if (!bcon)
44                 return 2;
45         return 0;
46 }
47
48 void OutputWinding (winding_t *w, FILE *glview)
49 {
50         static  int     level = 128;
51         vec_t           light;
52         int                     i;
53
54         fprintf (glview, "%i\n", w->numpoints);
55         level+=28;
56         light = (level&255)/255.0;
57         for (i=0 ; i<w->numpoints ; i++)
58         {
59                 fprintf (glview, "%6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
60                         w->p[i][0],
61                         w->p[i][1],
62                         w->p[i][2],
63                         light,
64                         light,
65                         light);
66         }
67         fprintf (glview, "\n");
68 }
69
70 /*
71 =============
72 OutputPortal
73 =============
74 */
75 void OutputPortal (portal_t *p, FILE *glview)
76 {
77         winding_t       *w;
78         int             sides;
79
80         sides = PortalVisibleSides (p);
81         if (!sides)
82                 return;
83
84         c_glfaces++;
85
86         w = p->winding;
87
88         if (sides == 2)         // back side
89                 w = ReverseWinding (w);
90
91         OutputWinding (w, glview);
92
93         if (sides == 2)
94                 FreeWinding(w);
95 }
96
97 /*
98 =============
99 WriteGLView_r
100 =============
101 */
102 void WriteGLView_r (node_t *node, FILE *glview)
103 {
104         portal_t        *p, *nextp;
105
106         if (node->planenum != PLANENUM_LEAF)
107         {
108                 WriteGLView_r (node->children[0], glview);
109                 WriteGLView_r (node->children[1], glview);
110                 return;
111         }
112
113         // write all the portals
114         for (p=node->portals ; p ; p=nextp)
115         {
116                 if (p->nodes[0] == node)
117                 {
118                         OutputPortal (p, glview);
119                         nextp = p->next[0];
120                 }
121                 else
122                         nextp = p->next[1];
123         }
124 }
125
126 /*
127 =============
128 WriteGLView
129 =============
130 */
131 void WriteGLView (tree_t *tree, char *source)
132 {
133         char    name[1024];
134         FILE    *glview;
135
136         c_glfaces = 0;
137         sprintf (name, "%s%s.gl",outbase, source);
138         Sys_Printf ("Writing %s\n", name);
139
140         glview = fopen (name, "w");
141         if (!glview)
142                 Error ("Couldn't open %s", name);
143         WriteGLView_r (tree->headnode, glview);
144         fclose (glview);
145
146         Sys_Printf ("%5i c_glfaces\n", c_glfaces);
147 }
148