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