gldraw.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include <windows.h>
  19. #include <GL/gl.h>
  20. #include <GL/glu.h>
  21. #include <GL/glaux.h>
  22. #include "qbsp.h"
  23. // can't use the glvertex3fv functions, because the vec3_t fields
  24. // could be either floats or doubles, depending on DOUBLEVEC_T
  25. qboolean drawflag;
  26. vec3_t draw_mins, draw_maxs;
  27. #define WIN_SIZE 512
  28. void InitWindow (void)
  29. {
  30. auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
  31. auxInitPosition (0, 0, WIN_SIZE, WIN_SIZE);
  32. auxInitWindow ("qcsg");
  33. }
  34. void Draw_ClearWindow (void)
  35. {
  36. static int init;
  37. int w, h, g;
  38. vec_t mx, my;
  39. if (!drawflag)
  40. return;
  41. if (!init)
  42. {
  43. init = true;
  44. InitWindow ();
  45. }
  46. glClearColor (1,0.8,0.8,0);
  47. glClear (GL_COLOR_BUFFER_BIT);
  48. w = (draw_maxs[0] - draw_mins[0]);
  49. h = (draw_maxs[1] - draw_mins[1]);
  50. mx = draw_mins[0] + w/2;
  51. my = draw_mins[1] + h/2;
  52. g = w > h ? w : h;
  53. glLoadIdentity ();
  54. gluPerspective (90, 1, 2, 16384);
  55. gluLookAt (mx, my, draw_maxs[2] + g/2, mx , my, draw_maxs[2], 0, 1, 0);
  56. glColor3f (0,0,0);
  57. // glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
  58. glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  59. glDisable (GL_DEPTH_TEST);
  60. glEnable (GL_BLEND);
  61. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  62. #if 0
  63. glColor4f (1,0,0,0.5);
  64. glBegin (GL_POLYGON);
  65. glVertex3f (0, 500, 0);
  66. glVertex3f (0, 900, 0);
  67. glVertex3f (0, 900, 100);
  68. glVertex3f (0, 500, 100);
  69. glEnd ();
  70. #endif
  71. glFlush ();
  72. }
  73. void Draw_SetRed (void)
  74. {
  75. if (!drawflag)
  76. return;
  77. glColor3f (1,0,0);
  78. }
  79. void Draw_SetGrey (void)
  80. {
  81. if (!drawflag)
  82. return;
  83. glColor3f (0.5,0.5,0.5);
  84. }
  85. void Draw_SetBlack (void)
  86. {
  87. if (!drawflag)
  88. return;
  89. glColor3f (0,0,0);
  90. }
  91. void DrawWinding (winding_t *w)
  92. {
  93. int i;
  94. if (!drawflag)
  95. return;
  96. glColor4f (0,0,0,0.5);
  97. glBegin (GL_LINE_LOOP);
  98. for (i=0 ; i<w->numpoints ; i++)
  99. glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
  100. glEnd ();
  101. glColor4f (0,1,0,0.3);
  102. glBegin (GL_POLYGON);
  103. for (i=0 ; i<w->numpoints ; i++)
  104. glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
  105. glEnd ();
  106. glFlush ();
  107. }
  108. void DrawAuxWinding (winding_t *w)
  109. {
  110. int i;
  111. if (!drawflag)
  112. return;
  113. glColor4f (0,0,0,0.5);
  114. glBegin (GL_LINE_LOOP);
  115. for (i=0 ; i<w->numpoints ; i++)
  116. glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
  117. glEnd ();
  118. glColor4f (1,0,0,0.3);
  119. glBegin (GL_POLYGON);
  120. for (i=0 ; i<w->numpoints ; i++)
  121. glVertex3f (w->p[i][0],w->p[i][1],w->p[i][2] );
  122. glEnd ();
  123. glFlush ();
  124. }
  125. //============================================================
  126. #define GLSERV_PORT 25001
  127. qboolean wins_init;
  128. int draw_socket;
  129. void GLS_BeginScene (void)
  130. {
  131. WSADATA winsockdata;
  132. WORD wVersionRequested;
  133. struct sockaddr_in address;
  134. int r;
  135. if (!wins_init)
  136. {
  137. wins_init = true;
  138. wVersionRequested = MAKEWORD(1, 1);
  139. r = WSAStartup (MAKEWORD(1, 1), &winsockdata);
  140. if (r)
  141. Error ("Winsock initialization failed.");
  142. }
  143. // connect a socket to the server
  144. draw_socket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
  145. if (draw_socket == -1)
  146. Error ("draw_socket failed");
  147. address.sin_family = AF_INET;
  148. address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  149. address.sin_port = GLSERV_PORT;
  150. r = connect (draw_socket, (struct sockaddr *)&address, sizeof(address));
  151. if (r == -1)
  152. {
  153. closesocket (draw_socket);
  154. draw_socket = 0;
  155. }
  156. }
  157. void GLS_Winding (winding_t *w, int code)
  158. {
  159. byte buf[1024];
  160. int i, j;
  161. if (!draw_socket)
  162. return;
  163. ((int *)buf)[0] = w->numpoints;
  164. ((int *)buf)[1] = code;
  165. for (i=0 ; i<w->numpoints ; i++)
  166. for (j=0 ; j<3 ; j++)
  167. ((float *)buf)[2+i*3+j] = w->p[i][j];
  168. send (draw_socket, buf, w->numpoints*12+8, 0);
  169. }
  170. void GLS_EndScene (void)
  171. {
  172. closesocket (draw_socket);
  173. draw_socket = 0;
  174. }