00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <windows.h>
00024 #include <GL/gl.h>
00025 #include <GL/glu.h>
00026 #include <GL/glaux.h>
00027
00028 #include "qbsp.h"
00029
00030
00031
00032
00033 qboolean drawflag;
00034 vec3_t draw_mins, draw_maxs;
00035
00036
00037 #define WIN_SIZE 512
00038
00039 void InitWindow (void)
00040 {
00041 auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
00042 auxInitPosition (0, 0, WIN_SIZE, WIN_SIZE);
00043 auxInitWindow ("qcsg");
00044 }
00045
00046 void Draw_ClearWindow (void)
00047 {
00048 static int init;
00049 int w, h, g;
00050 vec_t mx, my;
00051
00052 if (!drawflag)
00053 return;
00054
00055 if (!init)
00056 {
00057 init = true;
00058 InitWindow ();
00059 }
00060
00061 glClearColor (1,0.8,0.8,0);
00062 glClear (GL_COLOR_BUFFER_BIT);
00063
00064 w = (draw_maxs[0] - draw_mins[0]);
00065 h = (draw_maxs[1] - draw_mins[1]);
00066
00067 mx = draw_mins[0] + w/2;
00068 my = draw_mins[1] + h/2;
00069
00070 g = w > h ? w : h;
00071
00072 glLoadIdentity ();
00073 gluPerspective (90, 1, 2, 16384);
00074 gluLookAt (mx, my, draw_maxs[2] + g/2, mx , my, draw_maxs[2], 0, 1, 0);
00075
00076 glColor3f (0,0,0);
00077
00078 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
00079 glDisable (GL_DEPTH_TEST);
00080 glEnable (GL_BLEND);
00081 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00082
00083 #if 0
00084 glColor4f (1,0,0,0.5);
00085 glBegin (GL_POLYGON);
00086
00087 glVertex3f (0, 500, 0);
00088 glVertex3f (0, 900, 0);
00089 glVertex3f (0, 900, 100);
00090 glVertex3f (0, 500, 100);
00091
00092 glEnd ();
00093 #endif
00094
00095 glFlush ();
00096
00097 }
00098
00099 void Draw_SetRed (void)
00100 {
00101 if (!drawflag)
00102 return;
00103
00104 glColor3f (1,0,0);
00105 }
00106
00107 void Draw_SetGrey (void)
00108 {
00109 if (!drawflag)
00110 return;
00111
00112 glColor3f (0.5,0.5,0.5);
00113 }
00114
00115 void Draw_SetBlack (void)
00116 {
00117 if (!drawflag)
00118 return;
00119
00120 glColor3f (0,0,0);
00121 }
00122
00123 void DrawWinding (winding_t *w)
00124 {
00125 int i;
00126
00127 if (!drawflag)
00128 return;
00129
00130 glColor4f (0,0,0,0.5);
00131 glBegin (GL_LINE_LOOP);
00132 for (i=0 ; i<w->numpoints ; i++)
00133 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
00134 glEnd ();
00135
00136 glColor4f (0,1,0,0.3);
00137 glBegin (GL_POLYGON);
00138 for (i=0 ; i<w->numpoints ; i++)
00139 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
00140 glEnd ();
00141
00142 glFlush ();
00143 }
00144
00145 void DrawAuxWinding (winding_t *w)
00146 {
00147 int i;
00148
00149 if (!drawflag)
00150 return;
00151
00152 glColor4f (0,0,0,0.5);
00153 glBegin (GL_LINE_LOOP);
00154 for (i=0 ; i<w->numpoints ; i++)
00155 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
00156 glEnd ();
00157
00158 glColor4f (1,0,0,0.3);
00159 glBegin (GL_POLYGON);
00160 for (i=0 ; i<w->numpoints ; i++)
00161 glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
00162 glEnd ();
00163
00164 glFlush ();
00165 }
00166
00167
00168
00169 #define GLSERV_PORT 25001
00170
00171 qboolean wins_init;
00172 int draw_socket;
00173
00174 void GLS_BeginScene (void)
00175 {
00176 WSADATA winsockdata;
00177 WORD wVersionRequested;
00178 struct sockaddr_in address;
00179 int r;
00180
00181 if (!wins_init)
00182 {
00183 wins_init = true;
00184
00185 wVersionRequested = MAKEWORD(1, 1);
00186
00187 r = WSAStartup (MAKEWORD(1, 1), &winsockdata);
00188
00189 if (r)
00190 Error ("Winsock initialization failed.");
00191
00192 }
00193
00194
00195
00196 draw_socket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
00197 if (draw_socket == -1)
00198 Error ("draw_socket failed");
00199
00200 address.sin_family = AF_INET;
00201 address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
00202 address.sin_port = GLSERV_PORT;
00203 r = connect (draw_socket, (struct sockaddr *)&address, sizeof(address));
00204 if (r == -1)
00205 {
00206 closesocket (draw_socket);
00207 draw_socket = 0;
00208 }
00209 }
00210
00211 void GLS_Winding (winding_t *w, int code)
00212 {
00213 byte buf[1024];
00214 int i, j;
00215
00216 if (!draw_socket)
00217 return;
00218
00219 ((int *)buf)[0] = w->numpoints;
00220 ((int *)buf)[1] = code;
00221 for (i=0 ; i<w->numpoints ; i++)
00222 for (j=0 ; j<3 ; j++)
00223 ((float *)buf)[2+i*3+j] = w->p[i][j];
00224
00225 send (draw_socket, buf, w->numpoints*12+8, 0);
00226 }
00227
00228 void GLS_EndScene (void)
00229 {
00230 closesocket (draw_socket);
00231 draw_socket = 0;
00232 }