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