doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gldraw.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "dmap.h"
33 
34 #ifdef WIN32
35 #include <windows.h>
36 #include <GL/gl.h>
37 #include <GL/glu.h>
38 //#include <GL/glaux.h>
39 
40 #define WIN_SIZE 1024
41 
42 void Draw_ClearWindow( void ) {
43 
44  if ( !dmapGlobals.drawflag ) {
45  return;
46  }
47 
48  glDrawBuffer( GL_FRONT );
49 
50  RB_SetGL2D();
51 
52  glClearColor( 0.5, 0.5, 0.5, 0 );
53  glClear( GL_COLOR_BUFFER_BIT );
54 
55 #if 0
56  int w, h, g;
57  float mx, my;
58 
59  w = (dmapGlobals.drawBounds.b[1][0] - dmapGlobals.drawBounds.b[0][0]);
60  h = (dmapGlobals.drawBounds.b[1][1] - dmapGlobals.drawBounds.b[0][1]);
61 
62  mx = dmapGlobals.drawBounds.b[0][0] + w/2;
63  my = dmapGlobals.drawBounds.b[1][1] + h/2;
64 
65  g = w > h ? w : h;
66 
67  glLoadIdentity ();
68  gluPerspective (90, 1, 2, 16384);
69  gluLookAt (mx, my, draw_maxs[2] + g/2, mx , my, draw_maxs[2], 0, 1, 0);
70 #else
71  glMatrixMode( GL_PROJECTION );
72  glLoadIdentity ();
75  -1, 1 );
76  glMatrixMode( GL_MODELVIEW );
78 #endif
79  glColor3f (0,0,0);
80 // glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
81  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
82  glDisable (GL_DEPTH_TEST);
83 // glEnable (GL_BLEND);
84  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
85 
86 #if 0
87 //glColor4f (1,0,0,0.5);
88 // glBegin( GL_LINE_LOOP );
89  glBegin( GL_QUADS );
90 
91  glVertex2f( dmapGlobals.drawBounds.b[0][0] + 20, dmapGlobals.drawBounds.b[0][1] + 20 );
92  glVertex2f( dmapGlobals.drawBounds.b[1][0] - 20, dmapGlobals.drawBounds.b[0][1] + 20 );
93  glVertex2f( dmapGlobals.drawBounds.b[1][0] - 20, dmapGlobals.drawBounds.b[1][1] - 20 );
94  glVertex2f( dmapGlobals.drawBounds.b[0][0] + 20, dmapGlobals.drawBounds.b[1][1] - 20 );
95 
96  glEnd ();
97 #endif
98 
99  glFlush ();
100 
101 }
102 
103 void Draw_SetRed (void)
104 {
105  if (!dmapGlobals.drawflag)
106  return;
107 
108  glColor3f (1,0,0);
109 }
110 
111 void Draw_SetGrey (void)
112 {
113  if (!dmapGlobals.drawflag)
114  return;
115 
116  glColor3f( 0.5f, 0.5f, 0.5f);
117 }
118 
119 void Draw_SetBlack (void)
120 {
121  if (!dmapGlobals.drawflag)
122  return;
123 
124  glColor3f( 0.0f, 0.0f, 0.0f );
125 }
126 
127 void DrawWinding ( const idWinding *w )
128 {
129  int i;
130 
131  if (!dmapGlobals.drawflag)
132  return;
133 
134  glColor3f( 0.3f, 0.0f, 0.0f );
135  glBegin (GL_POLYGON);
136  for ( i = 0; i < w->GetNumPoints(); i++ )
137  glVertex3f( (*w)[i][0], (*w)[i][1], (*w)[i][2] );
138  glEnd ();
139 
140  glColor3f( 1, 0, 0 );
141  glBegin (GL_LINE_LOOP);
142  for ( i = 0; i < w->GetNumPoints(); i++ )
143  glVertex3f( (*w)[i][0], (*w)[i][1], (*w)[i][2] );
144  glEnd ();
145 
146  glFlush ();
147 }
148 
149 void DrawAuxWinding ( const idWinding *w)
150 {
151  int i;
152 
153  if (!dmapGlobals.drawflag)
154  return;
155 
156  glColor3f( 0.0f, 0.3f, 0.0f );
157  glBegin (GL_POLYGON);
158  for ( i = 0; i < w->GetNumPoints(); i++ )
159  glVertex3f( (*w)[i][0], (*w)[i][1], (*w)[i][2] );
160  glEnd ();
161 
162  glColor3f( 0.0f, 1.0f, 0.0f );
163  glBegin (GL_LINE_LOOP);
164  for ( i = 0; i < w->GetNumPoints(); i++ )
165  glVertex3f( (*w)[i][0], (*w)[i][1], (*w)[i][2] );
166  glEnd ();
167 
168  glFlush ();
169 }
170 
171 void DrawLine( idVec3 v1, idVec3 v2, int color ) {
172  if (!dmapGlobals.drawflag)
173  return;
174 
175  switch( color ) {
176  case 0: glColor3f( 0, 0, 0 ); break;
177  case 1: glColor3f( 0, 0, 1 ); break;
178  case 2: glColor3f( 0, 1, 0 ); break;
179  case 3: glColor3f( 0, 1, 1 ); break;
180  case 4: glColor3f( 1, 0, 0 ); break;
181  case 5: glColor3f( 1, 0, 1 ); break;
182  case 6: glColor3f( 1, 1, 0 ); break;
183  case 7: glColor3f( 1, 1, 1 ); break;
184  }
185 
186 
187  glBegin( GL_LINES );
188 
189  glVertex3fv( v1.ToFloatPtr() );
190  glVertex3fv( v2.ToFloatPtr() );
191 
192  glEnd();
193  glFlush();
194 }
195 
196 //============================================================
197 
198 #define GLSERV_PORT 25001
199 
200 bool wins_init;
201 int draw_socket;
202 
203 void GLS_BeginScene (void)
204 {
205  WSADATA winsockdata;
206  WORD wVersionRequested;
207  struct sockaddr_in address;
208  int r;
209 
210  if (!wins_init)
211  {
212  wins_init = true;
213 
214  wVersionRequested = MAKEWORD(1, 1);
215 
216  r = WSAStartup (MAKEWORD(1, 1), &winsockdata);
217 
218  if (r)
219  common->Error( "Winsock initialization failed.");
220 
221  }
222 
223  // connect a socket to the server
224 
225  draw_socket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
226  if (draw_socket == -1)
227  common->Error( "draw_socket failed");
228 
229  address.sin_family = AF_INET;
230  address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
231  address.sin_port = GLSERV_PORT;
232  r = connect (draw_socket, (struct sockaddr *)&address, sizeof(address));
233  if (r == -1)
234  {
235  closesocket (draw_socket);
236  draw_socket = 0;
237  }
238 }
239 
240 void GLS_Winding( const idWinding *w, int code )
241 {
242  byte buf[1024];
243  int i, j;
244 
245  if (!draw_socket)
246  return;
247 
248  ((int *)buf)[0] = w->GetNumPoints();
249  ((int *)buf)[1] = code;
250  for ( i = 0; i < w->GetNumPoints(); i++ )
251  for (j=0 ; j<3 ; j++)
252  ((float *)buf)[2+i*3+j] = (*w)[i][j];
253 
254  send (draw_socket, (const char *)buf, w->GetNumPoints() * 12 + 8, 0);
255 }
256 
257 void GLS_Triangle( const mapTri_t *tri, int code ) {
258  idWinding w;
259 
260  w.SetNumPoints( 3 );
261  VectorCopy( tri->v[0].xyz, w[0] );
262  VectorCopy( tri->v[1].xyz, w[1] );
263  VectorCopy( tri->v[2].xyz, w[2] );
264  GLS_Winding( &w, code );
265 }
266 
267 void GLS_EndScene (void)
268 {
269  closesocket (draw_socket);
270  draw_socket = 0;
271 }
272 #else
273 void Draw_ClearWindow( void ) {
274 }
275 
276 void DrawWinding( const idWinding *w) {
277 }
278 
279 void DrawAuxWinding ( const idWinding *w) {
280 }
281 
282 void GLS_Winding( const idWinding *w, int code ) {
283 }
284 
285 void GLS_BeginScene (void) {
286 }
287 
288 void GLS_EndScene (void)
289 {
290 }
291 
292 #endif
GLubyte g
Definition: glext.h:4662
byte color[4]
Definition: MegaTexture.cpp:54
void glClear(GLbitfield mask)
Definition: stub_gl.cpp:43
void glFlush(void)
Definition: stub_gl.cpp:123
void DrawLine(idVec3 v1, idVec3 v2, int color)
const float * ToFloatPtr(void) const
Definition: Vector.h:719
idVec3 xyz
Definition: DrawVert.h:42
#define VectorCopy(a, b)
Definition: Vector.h:1999
void glVertex2f(GLfloat x, GLfloat y)
Definition: stub_gl.cpp:356
Definition: Vector.h:316
void DrawWinding(const idWinding *w)
Definition: gldraw.cpp:276
void Draw_ClearWindow(void)
Definition: gldraw.cpp:273
void GLS_EndScene(void)
Definition: gldraw.cpp:288
void GLS_BeginScene(void)
Definition: gldraw.cpp:285
int i
Definition: process.py:33
void GLS_Triangle(const mapTri_t *tri, int code)
idDrawVert v[3]
Definition: dmap.h:67
void glBegin(GLenum mode)
Definition: stub_gl.cpp:37
GLfloat GLfloat GLfloat v2
Definition: glext.h:3608
void glDisable(GLenum cap)
Definition: stub_gl.cpp:96
int GetNumPoints(void) const
Definition: Winding.h:238
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3454
void DrawAuxWinding(const idWinding *w)
Definition: gldraw.cpp:279
void glEnd(void)
Definition: stub_gl.cpp:107
idCommon * common
Definition: Common.cpp:206
void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
Definition: stub_gl.cpp:364
void glBlendFunc(GLenum sfactor, GLenum dfactor)
Definition: stub_gl.cpp:40
bool drawflag
Definition: dmap.h:265
void glLoadIdentity(void)
Definition: stub_gl.cpp:201
idBounds drawBounds
Definition: dmap.h:264
GLfloat GLfloat v1
Definition: glext.h:3607
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
Definition: dmap.h:59
void RB_SetGL2D(void)
Definition: tr_backend.cpp:423
void glColor3f(GLfloat red, GLfloat green, GLfloat blue)
Definition: stub_gl.cpp:54
tuple f
Definition: idal.py:89
unsigned char byte
Definition: Lib.h:75
void GLS_Winding(const idWinding *w, int code)
Definition: gldraw.cpp:282
void glVertex3fv(const GLfloat *v)
Definition: stub_gl.cpp:365
GLuint address
Definition: glext.h:5165
void glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
Definition: stub_gl.cpp:45
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar)
Definition: stub_gl.cpp:233
GLint j
Definition: qgl.h:264
idVec3 b[2]
Definition: Bounds.h:109
dmapGlobals_t dmapGlobals
Definition: dmap.cpp:34
virtual void Error(const char *fmt,...) id_attribute((format(printf
void glMatrixMode(GLenum mode)
Definition: stub_gl.cpp:218
void glPolygonMode(GLenum face, GLenum mode)
Definition: stub_gl.cpp:244
void glDrawBuffer(GLenum mode)
Definition: stub_gl.cpp:99
void SetNumPoints(int n)
Definition: Winding.h:242