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