GlrRenW.cc 18.2 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
5
6
7
8
  Module:    GlrRenW.cc
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Ken Martin's avatar
Ken Martin committed
9
This file is part of the Visualization Toolkit. No part of this file or its
Ken Martin's avatar
Ken Martin committed
10
11
12
13
14
15
16
17
18
19
20
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994

=========================================================================*/
#include <math.h>
#include <iostream.h>
#include "GlrRenW.hh"
#include "GlrRen.hh"
#include "GlrProp.hh"
Ken Martin's avatar
Ken Martin committed
21
#include "GlrText.hh"
Ken Martin's avatar
Ken Martin committed
22
23
24
#include "GlrCam.hh"
#include "GlrLgt.hh"
#include "gl/glws.h"
Ken Martin's avatar
Ken Martin committed
25
#include "gl/get.h"
Ken Martin's avatar
Ken Martin committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

#define MAX_LIGHTS 8

#ifndef GD_MULTISAMPLE
#define GD_MULTISAMPLE 1000
#define GC_MS_SAMPLES 1000
void mssize() {return;}
long getgconfig() {return 1;}
void zbsize() {return;}
#endif

/* Declare the data structure for the GL rendering configuration needed */
static GLXconfig the_config[] = 
{
  { GLX_NORMAL,	GLX_RGB,	True} ,
  { GLX_NORMAL,	GLX_DOUBLE,	True} ,
  { GLX_NORMAL,	GLX_ZSIZE,	GLX_NOCONFIG} ,
  { GLX_NORMAL,	GLX_MSSAMPLE,	0} ,
  { GLX_NORMAL,	GLX_MSZSIZE,	0} ,
  { 0,		0,		0}
  };

static float tevprops[]
  = {
  TV_MODULATE, TV_NULL
    };

static unsigned long extract_config_value(int buffer,int mode,
					  GLXconfig *conf)
{
    int	i;
    for (i = 0; conf[i].buffer; i++)
	if (conf[i].buffer == buffer && conf[i].mode == mode)
	    return conf[i].arg;
    return 0;
}

static void set_config_value(int buffer,int mode,
			     GLXconfig *conf,unsigned long value)
{
  int	i;
  for (i = 0; conf[i].buffer; i++)
    {
    if (conf[i].buffer == buffer && conf[i].mode == mode)
      {
      conf[i].arg = (int)value;
      return;
      }
    }
}

/* Extract X visual information */
static XVisualInfo *extract_visual(int buffer,GLXconfig *conf,
				   Display *D,int S)
{
  XVisualInfo	templ;
  int n;
  
  templ.screen = S;
  templ.visualid = extract_config_value(buffer, GLX_VISUAL, conf);
  return XGetVisualInfo (D, VisualScreenMask|VisualIDMask, &templ, &n);
}

/* Fill the configuration structure with the appropriately */
/* created window */
static void set_window(int buffer,Window W,GLXconfig *conf)
{
    int	i;

    for (i = 0; conf[i].buffer; i++)
	if (conf[i].buffer == buffer && conf[i].mode == GLX_WINDOW)
	    conf[i].arg = (int)W;
}

Ken Martin's avatar
Ken Martin committed
100
vtkGlrRenderWindow::vtkGlrRenderWindow()
Will Schroeder's avatar
Will Schroeder committed
101
102
{
  this->Gid = -2;
103
  this->MultiSamples = 8;
Will Schroeder's avatar
Will Schroeder committed
104
105
106
107
  this->DisplayId = (Display *)NULL;
  this->WindowId = (Window)NULL;
  this->NextWindowId = (Window)NULL;
  this->ColorMap = (Colormap)0;
Ken Martin's avatar
Ken Martin committed
108
  this->StereoType = VTK_STEREO_CRYSTAL_EYES;
Will Schroeder's avatar
Will Schroeder committed
109

Ken Martin's avatar
Ken Martin committed
110
  strcpy(this->Name,"Visualization Toolkit - GL");
Will Schroeder's avatar
Will Schroeder committed
111
112
}

Ken Martin's avatar
Ken Martin committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Description:
// Resize the window.
vtkGlrRenderWindow::~vtkGlrRenderWindow()
{
  short cur_light;

  /* first delete all the old lights */
  for (cur_light = LIGHT0; cur_light < LIGHT0+MAX_LIGHTS; cur_light++)
    {
    lmbind(cur_light,0);
    }

  // then close the old window 
  if (this->OwnWindow)
    {
    XDestroyWindow(this->DisplayId,this->WindowId);
    }
  GLXunlink(this->DisplayId,this->WindowId);
  XSync(this->DisplayId,0);
}

Will Schroeder's avatar
Will Schroeder committed
134
135
// Description:
// Create a gl specific light.
Ken Martin's avatar
Ken Martin committed
136
vtkLightDevice *vtkGlrRenderWindow::MakeLight()
Ken Martin's avatar
Ken Martin committed
137
{
Ken Martin's avatar
Ken Martin committed
138
  vtkGlrLight *light;
Ken Martin's avatar
Ken Martin committed
139

Ken Martin's avatar
Ken Martin committed
140
141
  light = new vtkGlrLight;
  return (vtkLightDevice *)light;
Ken Martin's avatar
Ken Martin committed
142
143
}

Will Schroeder's avatar
Will Schroeder committed
144
145
// Description:
// Create a gl specific renderer.
Ken Martin's avatar
Ken Martin committed
146
vtkRenderer *vtkGlrRenderWindow::MakeRenderer()
Ken Martin's avatar
Ken Martin committed
147
{
Ken Martin's avatar
Ken Martin committed
148
  vtkGlrRenderer *ren;
Ken Martin's avatar
Ken Martin committed
149

Ken Martin's avatar
Ken Martin committed
150
  ren = new vtkGlrRenderer;
151
  this->AddRenderers(ren);
Ken Martin's avatar
Ken Martin committed
152
153

  // by default we are its parent
Ken Martin's avatar
Ken Martin committed
154
  ren->SetRenderWindow((vtkRenderWindow*)this);
Ken Martin's avatar
Ken Martin committed
155
  
Ken Martin's avatar
Ken Martin committed
156
  return (vtkRenderer *)ren;
Ken Martin's avatar
Ken Martin committed
157
158
}

Will Schroeder's avatar
Will Schroeder committed
159
160
// Description:
// Create a gl specific camera.
Ken Martin's avatar
Ken Martin committed
161
vtkCameraDevice *vtkGlrRenderWindow::MakeCamera()
Ken Martin's avatar
Ken Martin committed
162
{
Ken Martin's avatar
Ken Martin committed
163
  vtkGlrCamera *camera;
Ken Martin's avatar
Ken Martin committed
164

Ken Martin's avatar
Ken Martin committed
165
166
  camera = new vtkGlrCamera;
  return (vtkCameraDevice *)camera;
Ken Martin's avatar
Ken Martin committed
167
168
}

169
170
// Description:
// Create a gl specific property.
Ken Martin's avatar
Ken Martin committed
171
vtkPropertyDevice *vtkGlrRenderWindow::MakeProperty()
172
{
Ken Martin's avatar
Ken Martin committed
173
  vtkGlrProperty *property;
174

Ken Martin's avatar
Ken Martin committed
175
176
  property = new vtkGlrProperty;
  return (vtkPropertyDevice *)property;
177
178
}

Ken Martin's avatar
Ken Martin committed
179
180
// Description:
// Create a gl specific texture.
Ken Martin's avatar
Ken Martin committed
181
vtkTextureDevice *vtkGlrRenderWindow::MakeTexture()
Ken Martin's avatar
Ken Martin committed
182
{
Ken Martin's avatar
Ken Martin committed
183
  vtkGlrTexture *texture;
Ken Martin's avatar
Ken Martin committed
184

Ken Martin's avatar
Ken Martin committed
185
186
  texture = new vtkGlrTexture;
  return (vtkTextureDevice *)texture;
Ken Martin's avatar
Ken Martin committed
187
188
}

Will Schroeder's avatar
Will Schroeder committed
189
190
// Description:
// Begin the rendering process.
Ken Martin's avatar
Ken Martin committed
191
void vtkGlrRenderWindow::Start(void)
Ken Martin's avatar
Ken Martin committed
192
193
194
195
196
{
  // if the renderer has not been initialized, do so now
  if (this->Gid < 0)
    this->Initialize();

Ken Martin's avatar
Ken Martin committed
197
198
  // set the current window 
  GLXwinset(this->DisplayId,this->WindowId);
Ken Martin's avatar
Ken Martin committed
199
200
}

Will Schroeder's avatar
Will Schroeder committed
201
202
// Description:
// End the rendering process and display the image.
Ken Martin's avatar
Ken Martin committed
203
void vtkGlrRenderWindow::Frame(void)
Ken Martin's avatar
Ken Martin committed
204
205
206
207
{
  if (this->DoubleBuffer)
    {
    swapbuffers();
Ken Martin's avatar
Ken Martin committed
208
    vtkDebugMacro(<< " GL swapbuffers\n");
Ken Martin's avatar
Ken Martin committed
209
210
211
    }
}
 
Ken Martin's avatar
Ken Martin committed
212
213
214

// Description:
// Update system if needed due to stereo rendering.
Ken Martin's avatar
Ken Martin committed
215
void vtkGlrRenderWindow::StereoUpdate(void)
Ken Martin's avatar
Ken Martin committed
216
217
218
219
220
221
{
  // if stereo is on and it wasn't before
  if (this->StereoRender && (!this->StereoStatus))
    {
    switch (this->StereoType) 
      {
Ken Martin's avatar
Ken Martin committed
222
      case VTK_STEREO_CRYSTAL_EYES:
Ken Martin's avatar
Ken Martin committed
223
224
225
226
227
228
229
230
231
	{
	this->OldMonitorSetting = getmonitor();
	gflush();
	setmonitor(STR_RECT);
	gflush();
	// make sure we are in full screen
        this->StereoStatus = 1;
	this->FullScreenOn();
	}
232
	break;
Ken Martin's avatar
Ken Martin committed
233
      case VTK_STEREO_RED_BLUE:
234
235
236
	{
        this->StereoStatus = 1;
	}
Ken Martin's avatar
Ken Martin committed
237
238
239
240
241
242
      }
    }
  else if ((!this->StereoRender) && this->StereoStatus)
    {
    switch (this->StereoType) 
      {
Ken Martin's avatar
Ken Martin committed
243
      case VTK_STEREO_CRYSTAL_EYES:
Ken Martin's avatar
Ken Martin committed
244
245
246
247
248
249
250
251
252
	{
	/* restore the monitor */
	gflush();
	setmonitor(this->OldMonitorSetting);
	gflush();
	// make sure we are in full screen
        this->StereoStatus = 0;
	this->FullScreenOff();
	}
253
	break;
Ken Martin's avatar
Ken Martin committed
254
      case VTK_STEREO_RED_BLUE:
255
256
257
	{
        this->StereoStatus = 0;
	}
Ken Martin's avatar
Ken Martin committed
258
259
260
261
      }
    }
}

Will Schroeder's avatar
Will Schroeder committed
262
263
// Description:
// Specify various window parameters.
Ken Martin's avatar
Ken Martin committed
264
void vtkGlrRenderWindow::WindowConfigure()
Ken Martin's avatar
Ken Martin committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
{
  if (this->DoubleBuffer)
    {
    set_config_value(GLX_NORMAL,GLX_DOUBLE,the_config,True);
    }
  else
    {
    set_config_value(GLX_NORMAL,GLX_DOUBLE,the_config,False);
    }
  
  if (this->MultiSamples > 1.0)
    {
    set_config_value(GLX_NORMAL,GLX_ZSIZE,the_config,0);
    set_config_value(GLX_NORMAL,GLX_MSSAMPLE,the_config,
		     (unsigned long)this->MultiSamples);
    set_config_value(GLX_NORMAL,GLX_MSZSIZE,the_config,32);
    if (extract_config_value(GLX_NORMAL,GLX_MSSAMPLE,the_config)
	< this->MultiSamples) 
      {
Ken Martin's avatar
Ken Martin committed
284
      vtkDebugMacro(<< " Only got " << 
Ken Martin's avatar
Ken Martin committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
      extract_config_value(GLX_NORMAL,GLX_MSSAMPLE,the_config) 
      << " multisamples\n");
      this->MultiSamples =
	(int)extract_config_value(GLX_NORMAL,GLX_MSSAMPLE,the_config);
      }
    }
  if (this->MultiSamples <= 1.0)
    {
    set_config_value(GLX_NORMAL,GLX_ZSIZE,the_config,GLX_NOCONFIG);
    set_config_value(GLX_NORMAL,GLX_MSSAMPLE,the_config,0);
    set_config_value(GLX_NORMAL,GLX_MSZSIZE,the_config,0);
    }
}


Will Schroeder's avatar
Will Schroeder committed
300
301
// Description:
// Initialize the window for rendering.
Ken Martin's avatar
Ken Martin committed
302
void vtkGlrRenderWindow::WindowInitialize (void)
Ken Martin's avatar
Ken Martin committed
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
{
  GLXconfig  *conf;
  XVisualInfo  *v;
  XSetWindowAttributes	attr;
  Window  wins[2];
  int x,y,width,height;
  XWindowAttributes winattr;
  XSizeHints xsh;

  xsh.flags = USSize;
  if ((this->Position[0] >= 0)&&(this->Position[1] >= 0))
    {
    xsh.flags |= USPosition;
    xsh.x =  (int)(this->Position[0]);
    xsh.y =  (int)(this->Position[1]);
    }
  
  x = ((this->Position[0] >= 0) ? this->Position[0] : 5);
  y = ((this->Position[1] >= 0) ? this->Position[1] : 5);
  width = ((this->Size[0] > 0) ? this->Size[0] : 300);
  height = ((this->Size[1] > 0) ? this->Size[1] : 300);

  xsh.width  = width;
  xsh.height = height;

  // get the default display connection 
  if (!this->DisplayId)
    {
    this->DisplayId = XOpenDisplay((char *)NULL); 
    if (this->DisplayId == NULL) 
      {
Ken Martin's avatar
Ken Martin committed
334
      vtkErrorMacro(<< "bad X server connection.\n");
Ken Martin's avatar
Ken Martin committed
335
336
337
338
339
340
341
342
      }
    }

  // test for overlay planes 
  if ((conf = GLXgetconfig(this->DisplayId, 
			   DefaultScreen(this->DisplayId),
			   the_config)) == 0) 
    {
Ken Martin's avatar
Ken Martin committed
343
    vtkErrorMacro(<< "GL: getconfig failed\n");
Ken Martin's avatar
Ken Martin committed
344
345
346
    exit(1);
    }

Ken Martin's avatar
Ken Martin committed
347
348
349
350
351

  attr.override_redirect = False;
  if (this->Borders == 0.0)
    attr.override_redirect = True;
  
Ken Martin's avatar
Ken Martin committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  /* create our own window ? */
  this->OwnWindow = 0;
  if (!this->WindowId)
    {
    v = extract_visual(GLX_NORMAL,conf,this->DisplayId,
		       DefaultScreen(this->DisplayId));
    
    attr.colormap = extract_config_value(GLX_NORMAL, GLX_COLORMAP, conf);
    this->ColorMap = attr.colormap;

    attr.border_pixel = 0;
    this->WindowId = 
      XCreateWindow(this->DisplayId,
		    RootWindow(this->DisplayId,
			       DefaultScreen(this->DisplayId)), 
		    x, y, width, height, 0, v->depth, InputOutput, v->visual,
		    CWBorderPixel|CWColormap|CWOverrideRedirect, &attr);
    XStoreName(this->DisplayId, this->WindowId, this->Name);
    XSetNormalHints(this->DisplayId,this->WindowId,&xsh);
    this->OwnWindow = 1;
    }
Ken Martin's avatar
Ken Martin committed
373
374
375
376
377
378
379
  else
    {
    XChangeWindowAttributes(this->DisplayId,this->WindowId,
			    CWOverrideRedirect, &attr);
    }

  // RESIZE THE WINDOW TO THE DESIRED SIZE
Ken Martin's avatar
Ken Martin committed
380
  vtkDebugMacro(<< "Resizing the xwindow\n");
Ken Martin's avatar
Ken Martin committed
381
382
383
384
385
386
  XResizeWindow(this->DisplayId,this->WindowId,
		((this->Size[0] > 0) ? 
		 (int)(this->Size[0]) : 256),
		((this->Size[1] > 0) ? 
		 (int)(this->Size[1]) : 256));
  XSync(this->DisplayId,False);
Ken Martin's avatar
Ken Martin committed
387
388
389
390
391
392

  set_window(GLX_NORMAL, this->WindowId, conf);
  
  // Bind the GL to the created windows 
  if (GLXlink(this->DisplayId, conf) < 0) 
    {
Ken Martin's avatar
Ken Martin committed
393
    vtkErrorMacro("GL: Bind failed\n");
Ken Martin's avatar
Ken Martin committed
394
395
396
    exit(1);
    }

Ken Martin's avatar
Ken Martin committed
397
  vtkDebugMacro(" Mapping the xwindow\n");
Ken Martin's avatar
Ken Martin committed
398
399
400
401
402
403
404
405
406
407
408
409
  XMapWindow(this->DisplayId, this->WindowId);
  XSync(this->DisplayId,False);
  XGetWindowAttributes(this->DisplayId,
		       this->WindowId,&winattr);
  while (winattr.map_state == IsUnmapped)
    {
    XGetWindowAttributes(this->DisplayId,
			 this->WindowId,&winattr);
    };
  
  if (GLXwinset(this->DisplayId,this->WindowId) < 0)
    {
Ken Martin's avatar
Ken Martin committed
410
    vtkErrorMacro(<< "GL: winset failed\n");
Ken Martin's avatar
Ken Martin committed
411
412
413
    exit(1);
    }

Ken Martin's avatar
Ken Martin committed
414
  vtkDebugMacro(" mmode(MVIEWING)\n");
Ken Martin's avatar
Ken Martin committed
415
416
  mmode(MVIEWING);

Ken Martin's avatar
Ken Martin committed
417
  vtkDebugMacro(" zbuff stuff\n");
Ken Martin's avatar
Ken Martin committed
418
  zbuffer(TRUE);
Ken Martin's avatar
Ken Martin committed
419

Ken Martin's avatar
Ken Martin committed
420
  vtkDebugMacro(" subpixel stuff\n");
Ken Martin's avatar
Ken Martin committed
421
  subpixel(TRUE);
Ken Martin's avatar
Ken Martin committed
422
 
Ken Martin's avatar
Ken Martin committed
423
  vtkDebugMacro(" texture stuff\n");
Ken Martin's avatar
Ken Martin committed
424
425
426
427
428
429
  if (getgdesc(GD_TEXTURE))
    {
    tevdef(1,0,tevprops);
    tevbind(TV_ENV0,1);
    }

Ken Martin's avatar
Ken Martin committed
430
  vtkDebugMacro("% alpha stuff\n");
Ken Martin's avatar
Ken Martin committed
431
432
433
434
435
436
437
438
  if (getgdesc(GD_AFUNCTION))
    {
    afunction(0,AF_NOTEQUAL);
    }

  /*
   * initialize blending for transparency
   */
Ken Martin's avatar
Ken Martin committed
439
  vtkDebugMacro(" blend func stuff\n");
Ken Martin's avatar
Ken Martin committed
440
441
442
443
444
  blendfunction(BF_SA, BF_MSA);

  this->Mapped = 1;
}

Will Schroeder's avatar
Will Schroeder committed
445
446
// Description:
// Initialize the rendering window.
Ken Martin's avatar
Ken Martin committed
447
void vtkGlrRenderWindow::Initialize (void)
Ken Martin's avatar
Ken Martin committed
448
449
450
451
452
453
454
455
456
457
458
459
460
461
{
  // make sure we havent already been initialized 
  if (this->Gid >= 0)
    return;

  this->Connect();

  // now initialize the window 
  this->WindowConfigure();
  this->WindowInitialize();

  this->Gid = 1;
}

Will Schroeder's avatar
Will Schroeder committed
462
463
// Description:
// Make the connection to the window manager.
Ken Martin's avatar
Ken Martin committed
464
void vtkGlrRenderWindow::Connect()
Ken Martin's avatar
Ken Martin committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
{
  int status = -1;

  // make sure we haven't already opened 
  if (this->Gid > -2)
    {
    return;
    }

  /* get the default display connection */
  if (!this->DisplayId)
    {
    this->DisplayId = XOpenDisplay((char *)NULL); 
    if (this->DisplayId == NULL) 
      {
Ken Martin's avatar
Ken Martin committed
480
      vtkErrorMacro(<< "bad X server connection.\n");
Ken Martin's avatar
Ken Martin committed
481
482
483
484
485
486
487
488
489
      }
    }
  else
    {
    if ((status = (int)dglopen (DisplayString(this->DisplayId), DGLLOCAL)) < 0)
      {
      /* try local host */
      if ((status = (int)dglopen ("localhost:0.0", DGLLOCAL)) < 0)
	{
Ken Martin's avatar
Ken Martin committed
490
	vtkErrorMacro(<< " error from glopen : " << status << endl);
Ken Martin's avatar
Ken Martin committed
491
492
493
494
495
	exit(-1);
	}
      else
	{
	/* this is recoverable */
Ken Martin's avatar
Ken Martin committed
496
	vtkErrorMacro(<< " error2 from glopen : " << status << endl);
Ken Martin's avatar
Ken Martin committed
497
498
499
500
501
502
503
504
	exit(-1);
	}
      }
    }

  this->Gid = -1;
}

Will Schroeder's avatar
Will Schroeder committed
505
506
// Description:
// Change the window to fill the entire screen.
Ken Martin's avatar
Ken Martin committed
507
void vtkGlrRenderWindow::SetFullScreen(int arg)
Ken Martin's avatar
Ken Martin committed
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
{
  int *temp;
  
  if (this->FullScreen == arg) return;
  
  if (!this->Mapped)
    {
    this->PrefFullScreen();
    return;
    }

  // set the mode 
  this->FullScreen = arg;
  if (this->FullScreen <= 0)
    {
    this->Position[0] = this->OldScreen[0];
    this->Position[1] = this->OldScreen[1];
    this->Size[0] = this->OldScreen[2]; 
    this->Size[1] = this->OldScreen[3];
    this->Borders = this->OldScreen[4];
    }
  else
    {
    // if window already up get its values 
    if (this->WindowId)
      {
      XWindowAttributes attribs;
      
      //  Find the current window size 
      XGetWindowAttributes(this->DisplayId, 
			   this->WindowId, &attribs);
      
      this->OldScreen[2] = attribs.width;
      this->OldScreen[3] = attribs.height;;

      temp = this->GetPosition();      
      this->OldScreen[0] = temp[0];
      this->OldScreen[1] = temp[1];

      this->OldScreen[4] = this->Borders;
      this->PrefFullScreen();
      }
    }
  
  // remap the window 
  this->WindowRemap();

  // if full screen then grab the keyboard 
  if (this->FullScreen)
    {
    XGrabKeyboard(this->DisplayId,this->WindowId,
		  False,GrabModeAsync,GrabModeAsync,CurrentTime);
    }
  this->Modified();
}

Will Schroeder's avatar
Will Schroeder committed
564
565
// Description:
// Set the preferred window size to full screen.
Ken Martin's avatar
Ken Martin committed
566
void vtkGlrRenderWindow::PrefFullScreen()
Ken Martin's avatar
Ken Martin committed
567
568
569
570
571
572
573
574
575
576
577
578
579
{
  this->Connect();

  // use full screen 
  this->Position[0] = 0;
  this->Position[1] = 0;
  this->Size[0] = (int)getgdesc(GD_XPMAX);
  this->Size[1] = (int)getgdesc(GD_YPMAX);

  // don't show borders 
  this->Borders = 0;
}

Will Schroeder's avatar
Will Schroeder committed
580
581
// Description:
// Resize the window.
Ken Martin's avatar
Ken Martin committed
582
void vtkGlrRenderWindow::WindowRemap()
Ken Martin's avatar
Ken Martin committed
583
584
585
586
587
588
589
590
591
592
{
  short cur_light;

  /* first delete all the old lights */
  for (cur_light = LIGHT0; cur_light < LIGHT0+MAX_LIGHTS; cur_light++)
    {
    lmbind(cur_light,0);
    }

  // then close the old window 
Ken Martin's avatar
Ken Martin committed
593
594
595
596
  if (this->OwnWindow)
    {
    XDestroyWindow(this->DisplayId,this->WindowId);
    }
Ken Martin's avatar
Ken Martin committed
597
598
599
  GLXunlink(this->DisplayId,this->WindowId);
  // set the default windowid 
  this->WindowId = this->NextWindowId;
600
  this->NextWindowId = (Window)NULL;
Ken Martin's avatar
Ken Martin committed
601
602
603
604
605
606

  /* configure the window */
  this->WindowConfigure();
  this->WindowInitialize();
}

Will Schroeder's avatar
Will Schroeder committed
607
608
// Description:
// Specify the size of the rendering window.
Ken Martin's avatar
Ken Martin committed
609
void vtkGlrRenderWindow::SetSize(int x,int y)
Ken Martin's avatar
Ken Martin committed
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
{
  // if we arent mappen then just set the ivars 
  if (!this->Mapped)
    {
    if ((this->Size[0] != x)||(this->Size[1] != y))
      {
      this->Modified();
      }
    this->Size[0] = x;
    this->Size[1] = y;
    return;
    }

  XResizeWindow(this->DisplayId,this->WindowId,x,y);
  XSync(this->DisplayId,False);
}


Ken Martin's avatar
Ken Martin committed
628

Ken Martin's avatar
Ken Martin committed
629
int vtkGlrRenderWindow::GetDesiredDepth()
Ken Martin's avatar
Ken Martin committed
630
{
Ken Martin's avatar
Ken Martin committed
631
632
  GLXconfig *conf;
  XVisualInfo *v;
Ken Martin's avatar
Ken Martin committed
633

Ken Martin's avatar
Ken Martin committed
634
  this->Connect();
Ken Martin's avatar
Ken Martin committed
635

Ken Martin's avatar
Ken Martin committed
636
637
638
639
  if ((conf = GLXgetconfig(this->DisplayId, 
			   DefaultScreen(this->DisplayId),
			   the_config)) == 0) 
    {
Ken Martin's avatar
Ken Martin committed
640
    vtkErrorMacro(<< "GL: getconfig failed\n");
Ken Martin's avatar
Ken Martin committed
641
642
643
644
645
646
    exit(1);
    }

  /* get the default visual to use */
  v = extract_visual(GLX_NORMAL,conf,this->DisplayId,
		     DefaultScreen(this->DisplayId));
Ken Martin's avatar
Ken Martin committed
647

Ken Martin's avatar
Ken Martin committed
648
  return v->depth;  
Ken Martin's avatar
Ken Martin committed
649
650
}

Will Schroeder's avatar
Will Schroeder committed
651
// Description:
Ken Martin's avatar
Ken Martin committed
652
// Get a visual from the windowing system.
Ken Martin's avatar
Ken Martin committed
653
Visual *vtkGlrRenderWindow::GetDesiredVisual ()
Ken Martin's avatar
Ken Martin committed
654
{
Ken Martin's avatar
Ken Martin committed
655
656
657
658
659
660
661
662
663
  XVisualInfo  *v;
  GLXconfig *conf;

  this->Connect();

  if ((conf = GLXgetconfig(this->DisplayId, 
			   DefaultScreen(this->DisplayId),
			   the_config)) == 0) 
    {
Ken Martin's avatar
Ken Martin committed
664
    vtkErrorMacro(<< "GL: getconfig failed\n");
Ken Martin's avatar
Ken Martin committed
665
666
667
668
669
670
    exit(1);
    }

  /* get the default visual to use */
  v = extract_visual(GLX_NORMAL,conf,this->DisplayId,
		     DefaultScreen(this->DisplayId));
Ken Martin's avatar
Ken Martin committed
671

Ken Martin's avatar
Ken Martin committed
672
  return v->visual;  
Ken Martin's avatar
Ken Martin committed
673
674
}

Ken Martin's avatar
Ken Martin committed
675

Will Schroeder's avatar
Will Schroeder committed
676
// Description:
Ken Martin's avatar
Ken Martin committed
677
// Get a colormap from the windowing system.
Ken Martin's avatar
Ken Martin committed
678
Colormap vtkGlrRenderWindow::GetDesiredColormap ()
Ken Martin's avatar
Ken Martin committed
679
{
Ken Martin's avatar
Ken Martin committed
680
681
682
683
684
685
686
687
688
689
690
  GLXconfig *conf;
  XVisualInfo *v;

  if (this->ColorMap) return this->ColorMap;

  this->Connect();

  if ((conf = GLXgetconfig(this->DisplayId, 
			   DefaultScreen(this->DisplayId),
			   the_config)) == 0) 
    {
Ken Martin's avatar
Ken Martin committed
691
    vtkErrorMacro(<< "GL: getconfig failed\n");
Ken Martin's avatar
Ken Martin committed
692
693
694
695
696
    exit(1);
    }

  /* get the default colormap to use */
  this->ColorMap = extract_config_value(GLX_NORMAL, GLX_COLORMAP, conf);
Ken Martin's avatar
Ken Martin committed
697

Ken Martin's avatar
Ken Martin committed
698
  return this->ColorMap;  
Ken Martin's avatar
Ken Martin committed
699
700
}

Ken Martin's avatar
Ken Martin committed
701
void vtkGlrRenderWindow::PrintSelf(ostream& os, vtkIndent indent)
Ken Martin's avatar
Ken Martin committed
702
{
Ken Martin's avatar
Ken Martin committed
703
  this->vtkXRenderWindow::PrintSelf(os,indent);
Ken Martin's avatar
Ken Martin committed
704

705
706
  os << indent << "Gid: " << this->Gid << "\n";
  os << indent << "MultiSamples: " << this->MultiSamples << "\n";
Ken Martin's avatar
Ken Martin committed
707
}
708
709


710
711
unsigned char *vtkGlrRenderWindow::GetPixelData(int x1, int y1, int x2, int y2,
						int front)
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
{
  long     xloop,yloop;
  int     y_low, y_hi;
  int     x_low, x_hi;
  unsigned long   *buffer;
  unsigned char   *data = NULL;
  unsigned char   *p_data = NULL;

  /* set the current window */
  GLXwinset(this->DisplayId,this->WindowId);

  buffer = new unsigned long[abs(x2 - x1)+1];
  data = new unsigned char[(abs(x2 - x1) + 1)*(abs(y2 - y1) + 1)*3];

  if (y1 < y2)
    {
    y_low = y1; 
    y_hi  = y2;
    }
  else
    {
    y_low = y2; 
    y_hi  = y1;
    }

  if (x1 < x2)
    {
    x_low = x1; 
    x_hi  = x2;
    }
  else
    {
    x_low = x2; 
    x_hi  = x1;
    }

748
749
750
751
752
753
754
755
  if (front)
    {
    readsource(SRC_FRONT);
    }
  else
    { 
    readsource(SRC_BACK);
    }
756
  p_data = data;
Ken Martin's avatar
Ken Martin committed
757
  for (yloop = y_low; yloop <= y_hi; yloop++)
758
759
760
761
762
763
764
765
766
767
768
    {
    // read in a row of pixels 
    lrectread(x_low,yloop,x_hi,yloop,buffer);
    for (xloop = 0; xloop <= (abs(x2-x1)); xloop++)
      {
      *p_data = buffer[xloop] & (0x000000ff); p_data++;
      *p_data = (buffer[xloop] & (0x0000ff00)) >> 8; p_data++;
      *p_data = (buffer[xloop] & (0x00ff0000)) >> 16; p_data++;
      }
    }
  
Ken Martin's avatar
Ken Martin committed
769
  delete [] buffer;
770
771
772
773

  return data;
}

Ken Martin's avatar
Ken Martin committed
774
void vtkGlrRenderWindow::SetPixelData(int x1, int y1, int x2, int y2,
Ken Martin's avatar
Ken Martin committed
775
				     unsigned char *data, int front)
776
777
778
779
780
781
782
783
784
785
786
787
{
  int     y_low, y_hi;
  int     x_low, x_hi;
  int     xloop,yloop;
  unsigned long   *buffer;
  unsigned char   *p_data = NULL;

  // set the current window 
  GLXwinset(this->DisplayId,this->WindowId);

  if (this->DoubleBuffer)
    {
788
789
790
791
792
793
794
795
    if (front)
      {
      frontbuffer(TRUE);
      }
    else
      {
      backbuffer(FALSE);
      }
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
    }
  dither(DT_OFF);

  buffer = new unsigned long[4*(abs(x2 - x1)+1)];

  if (y1 < y2)
    {
    y_low = y1; 
    y_hi  = y2;
    }
  else
    {
    y_low = y2; 
    y_hi  = y1;
    }
  
  if (x1 < x2)
    {
    x_low = x1; 
    x_hi  = x2;
    }
  else
    {
    x_low = x2; 
    x_hi  = x1;
    }
  
  viewport(x_low,x_hi,y_low,y_hi);

  /* now write the binary info one row at a time */
  p_data = data;
Ken Martin's avatar
Ken Martin committed
827
  for (yloop = y_low; yloop <= y_hi; yloop++)
828
829
830
831
832
833
834
835
836
837
838
    {
    for (xloop = 0; xloop <= (abs(x2-x1)); xloop++)
      {
      buffer[xloop] = 0xff000000 + *p_data; p_data++; 
      buffer[xloop] += (*p_data) << 8; p_data++;
      buffer[xloop] += (*p_data) << 16; p_data++;
      }
    /* write out a row of pixels */
    lrectwrite(x_low,yloop,x_hi,yloop,buffer);
    }
  
Ken Martin's avatar
Ken Martin committed
839
  delete [] buffer;
840
841
842

  dither(DT_ON);
}