Debian Codegraph @

tools/quake2/extra/bsp/qbsp3/gldraw.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
4
5 This file is part of Quake 2 Tools source code.
6
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, 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 Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #include <windows.h>
24 #include <GL/gl.h>
25 #include <GL/glu.h>
26 #include <GL/glaux.h>
27
28 #include "qbsp.h"
29
30 // can't use the glvertex3fv functions, because the vec3_t fields
31 // could be either floats or doubles, depending on DOUBLEVEC_T
32
33 qboolean drawflag;
34 vec3_t draw_mins, draw_maxs;
35
36
37 #define WIN_SIZE 512
38
39 void InitWindow (void)
40 {
41 auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
42 auxInitPosition (0, 0, WIN_SIZE, WIN_SIZE);
43 auxInitWindow ("qcsg");
44 }
45
46 void Draw_ClearWindow (void)
47 {
48 static int init;
49 int w, h, g;
50 vec_t mx, my;
51
52 if (!drawflag)
53 return;
54
55 if (!init)
56 {
57 init = true;
58 InitWindow ();
59 }
60
61 glClearColor (1,0.8,0.8,0);
62 glClear (GL_COLOR_BUFFER_BIT);
63
64 w = (draw_maxs[0] - draw_mins[0]);
65 h = (draw_maxs[1] - draw_mins[1]);
66
67 mx = draw_mins[0] + w/2;
68 my = draw_mins[1] + h/2;
69
70 g = w > h ? w : h;
71
72 glLoadIdentity ();
73 gluPerspective (90, 1, 2, 16384);
74 gluLookAt (mx, my, draw_maxs[2] + g/2, mx , my, draw_maxs[2], 0, 1, 0);
75
76 glColor3f (0,0,0);
77 // glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
78 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
79 glDisable (GL_DEPTH_TEST);
80 glEnable (GL_BLEND);
81 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
82
83 #if 0
84 glColor4f (1,0,0,0.5);
85 glBegin (GL_POLYGON);
86
87 glVertex3f (0, 500, 0);
88 glVertex3f (0, 900, 0);
89 glVertex3f (0, 900, 100);
90 glVertex3f (0, 500, 100);
91
92 glEnd ();
93 #endif
94
95 glFlush ();
96
97 }
98
99 void Draw_SetRed (void)
100 {
101 if (!drawflag)
102 return;
103
104 glColor3f (1,0,0);
105 }
106
107 void Draw_SetGrey (void)
108 {
109 if (!drawflag)
110 return;
111
112 glColor3f (0.5,0.5,0.5);
113 }
114
115 void Draw_SetBlack (void)
116 {
117 if (!drawflag)
118 return;
119
120 glColor3f (0,0,0);
121 }
122
123 void DrawWinding (winding_t *w)
124 {
125 int i;
126
127 if (!drawflag)
128 return;
129
130 glColor4f (0,0,0,0.5);
131 glBegin (GL_LINE_LOOP);
132 for (i=0 ; i<w->numpoints ; i++)
133 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
134 glEnd ();
135
136 glColor4f (0,1,0,0.3);
137 glBegin (GL_POLYGON);
138 for (i=0 ; i<w->numpoints ; i++)
139 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
140 glEnd ();
141
142 glFlush ();
143 }
144
145 void DrawAuxWinding (winding_t *w)
146 {
147 int i;
148
149 if (!drawflag)
150 return;
151
152 glColor4f (0,0,0,0.5);
153 glBegin (GL_LINE_LOOP);
154 for (i=0 ; i<w->numpoints ; i++)
155 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
156 glEnd ();
157
158 glColor4f (1,0,0,0.3);
159 glBegin (GL_POLYGON);
160 for (i=0 ; i<w->numpoints ; i++)
161 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
162 glEnd ();
163
164 glFlush ();
165 }
166
167 //============================================================
168
169 #define GLSERV_PORT 25001
170
171 qboolean wins_init;
172 int draw_socket;
173
174 void GLS_BeginScene (void)
175 {
176 WSADATA winsockdata;
177 WORD wVersionRequested;
178 struct sockaddr_in address;
179 int r;
180
181 if (!wins_init)
182 {
183 wins_init = true;
184
185 wVersionRequested = MAKEWORD(1, 1);
186
187 r = WSAStartup (MAKEWORD(1, 1), &winsockdata);
188
189 if (r)
190 Error ("Winsock initialization failed.");
191
192 }
193
194 // connect a socket to the server
195
196 draw_socket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
197 if (draw_socket == -1)
198 Error ("draw_socket failed");
199
200 address.sin_family = AF_INET;
201 address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
202 address.sin_port = GLSERV_PORT;
203 r = connect (draw_socket, (struct sockaddr *)&address, sizeof(address));
204 if (r == -1)
205 {
206 closesocket (draw_socket);
207 draw_socket = 0;
208 }
209 }
210
211 void GLS_Winding (winding_t *w, int code)
212 {
213 byte buf[1024];
214 int i, j;
215
216 if (!draw_socket)
217 return;
218
219 ((int *)buf)[0] = w->numpoints;
220 ((int *)buf)[1] = code;
221 for (i=0 ; i<w->numpoints ; i++)
222 for (j=0 ; j<3 ; j++)
223 ((float *)buf)[2+i*3+j] = w->p[i][j];
224
225 send (draw_socket, buf, w->numpoints*12+8, 0);
226 }
227
228 void GLS_EndScene (void)
229 {
230 closesocket (draw_socket);
231 draw_socket = 0;
232 }