vtkWin32OpenGLRenderWindow.cxx 45.5 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
3
/*=========================================================================

Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
Module:    vtkWin32OpenGLRenderWindow.cxx
Ken Martin's avatar
Ken Martin committed
5
6
7
8
9
10
11
12
13
14

Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
Ken Martin's avatar
Ken Martin committed
15
#include "vtkWin32OpenGLRenderWindow.h"
Ken Martin's avatar
Ken Martin committed
16
17
18

#include "vtkIdList.h"
#include "vtkCommand.h"
19
#include "vtkNew.h"
Ken Martin's avatar
Ken Martin committed
20
#include "vtkObjectFactory.h"
21
22
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLRenderWindow.h"
Ken Martin's avatar
Ken Martin committed
23
#include "vtkOpenGLError.h"
24
#include "vtkOpenGLShaderCache.h"
Ken Martin's avatar
Ken Martin committed
25
#include "vtkRendererCollection.h"
26
#include "vtkStringOutputWindow.h"
27
#include "vtkWin32RenderWindowInteractor.h"
Ken Martin's avatar
Ken Martin committed
28

Sean McBride's avatar
Sean McBride committed
29
#include <cmath>
30
#include <sstream>
Ken Martin's avatar
Ken Martin committed
31
32
33

#include "vtkOpenGLError.h"

34
35
36
37
38
39
40
// Mouse wheel support
// In an ideal world we would just have to include <zmouse.h>, but it is not
// always available with all compilers/headers
#ifndef WM_MOUSEWHEEL
#  define WM_MOUSEWHEEL                   0x020A
#endif  //WM_MOUSEWHEEL

Ken Martin's avatar
Ken Martin committed
41
vtkStandardNewMacro(vtkWin32OpenGLRenderWindow);
Ken Martin's avatar
Ken Martin committed
42

Ken Martin's avatar
Ken Martin committed
43
vtkWin32OpenGLRenderWindow::vtkWin32OpenGLRenderWindow()
Ken Martin's avatar
Ken Martin committed
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
{
  this->ApplicationInstance =  NULL;
  this->Palette = NULL;
  this->ContextId = 0;
  this->WindowId = 0;
  this->ParentId = 0;
  this->NextWindowId = 0;
  this->DeviceContext = (HDC)0;         // hsr
  this->MFChandledWindow = FALSE;       // hsr
  this->StereoType = VTK_STEREO_CRYSTAL_EYES;
  this->CursorHidden = 0;
  this->Capabilities = 0;

  this->ScreenDeviceContext = (HDC)0;
  this->MemoryHdc = (HDC)0;
  this->CreatingOffScreenWindow = 0;
  this->WindowIdReferenceCount = 0;

  this->ScreenMapped = this->Mapped;
  this->ScreenWindowSize[0] = this->Size[0];
  this->ScreenWindowSize[1] = this->Size[1];
  this->ScreenDeviceContext = this->DeviceContext;
  this->ScreenDoubleBuffer = this->DoubleBuffer;
  this->ScreenContextId = this->ContextId;
}

Ken Martin's avatar
Ken Martin committed
70
vtkWin32OpenGLRenderWindow::~vtkWin32OpenGLRenderWindow()
Ken Martin's avatar
Ken Martin committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{
  this->Finalize();

  vtkRenderer *ren;
  vtkCollectionSimpleIterator rit;
  this->Renderers->InitTraversal(rit);
  while ( (ren = this->Renderers->GetNextRenderer(rit)) )
    {
    ren->SetRenderWindow(NULL);
    }

  delete[] this->Capabilities;
}

Ken Martin's avatar
Ken Martin committed
85
void vtkWin32OpenGLRenderWindow::Clean()
Ken Martin's avatar
Ken Martin committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
  /* finish OpenGL rendering */
  if (this->OwnContext && this->ContextId)
    {
    this->MakeCurrent();
    this->CleanUpRenderers();

    // Note: wglMakeCurrent(NULL,NULL) is valid according to the documentation
    // and works with nVidia and ATI but not with Intel. Passing an existing
    // device context works in any case.
    // see VTK Bug 7119.
    if(wglMakeCurrent(this->DeviceContext,NULL)!=TRUE)
      {
      vtkErrorMacro("wglMakeCurrent failed in Clean(), error: " << GetLastError());
      }
    if (wglDeleteContext(this->ContextId) != TRUE)
      {
      vtkErrorMacro("wglDeleteContext failed in Clean(), error: " << GetLastError());
      }
    }
  this->ContextId = NULL;

  if (this->Palette)
    {
    SelectPalette(this->DeviceContext, this->OldPalette, FALSE); // SVA delete the old palette
    DeleteObject(this->Palette);
    this->Palette = NULL;
    }
}

Ken Martin's avatar
Ken Martin committed
116
void vtkWin32OpenGLRenderWindow::CleanUpRenderers()
Ken Martin's avatar
Ken Martin committed
117
118
119
120
{
  // tell each of the renderers that this render window/graphics context
  // is being removed (the RendererCollection is removed by vtkRenderWindow's
  // destructor)
121
  this->ReleaseGraphicsResources(this);
Ken Martin's avatar
Ken Martin committed
122
123
}

Ken Martin's avatar
Ken Martin committed
124
LRESULT APIENTRY vtkWin32OpenGLRenderWindow::WndProc(HWND hWnd, UINT message,
Ken Martin's avatar
Ken Martin committed
125
126
127
128
129
                                                     WPARAM wParam,
                                                     LPARAM lParam)
{
  LRESULT res;

Ken Martin's avatar
Ken Martin committed
130
131
  vtkWin32OpenGLRenderWindow *me =
    (vtkWin32OpenGLRenderWindow *)vtkGetWindowLong(hWnd,sizeof(vtkLONG));
Ken Martin's avatar
Ken Martin committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

  if (me && me->GetReferenceCount()>0)
    {
    me->Register(me);
    res = me->MessageProc(hWnd, message, wParam, lParam);
    me->UnRegister(me);
    }
  else
    {
    res = DefWindowProc(hWnd, message, wParam, lParam);
    }

  return res;
}

Ken Martin's avatar
Ken Martin committed
147
void vtkWin32OpenGLRenderWindow::SetWindowName( const char * _arg )
Ken Martin's avatar
Ken Martin committed
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
  vtkWindow::SetWindowName(_arg);
  if (this->WindowId)
    {
#ifdef UNICODE
    wchar_t *wname = new wchar_t [mbstowcs(NULL, this->WindowName, 32000)+1];
    mbstowcs(wname, this->WindowName, 32000);
    SetWindowText(this->WindowId, wname);
    delete [] wname;
#else
    SetWindowText(this->WindowId, this->WindowName);
#endif
    }
}

Ken Martin's avatar
Ken Martin committed
163
int vtkWin32OpenGLRenderWindow::GetEventPending()
Ken Martin's avatar
Ken Martin committed
164
165
166
167
168
169
170
171
172
173
{
  MSG msg;
  if (PeekMessage(&msg,this->WindowId,WM_MOUSEFIRST,WM_MOUSELAST,PM_NOREMOVE))
    {
    if (msg.message == WM_MOUSEMOVE)
      {
      PeekMessage(&msg,this->WindowId,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE);
      }
    if ((msg.message == WM_LBUTTONDOWN) ||
        (msg.message == WM_RBUTTONDOWN) ||
174
175
        (msg.message == WM_MBUTTONDOWN) ||
        (msg.message == WM_MOUSEWHEEL))
Ken Martin's avatar
Ken Martin committed
176
177
178
179
180
181
182
183
184
      {
      return 1;
      }
    }

  return 0;
}

// ----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
185
bool vtkWin32OpenGLRenderWindow::InitializeFromCurrentContext()
Ken Martin's avatar
Ken Martin committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
{
  HGLRC currentContext = wglGetCurrentContext();
  if (currentContext != NULL)
    {
    this->SetWindowId(WindowFromDC(wglGetCurrentDC()));
    this->SetDeviceContext(wglGetCurrentDC());
    this->SetContextId(currentContext);
    this->OpenGLInit();
    this->OwnContext = 0;
    return true;
    }
  return false;
}

// ----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
201
void vtkWin32OpenGLRenderWindow::MakeCurrent()
Ken Martin's avatar
Ken Martin committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
{
  // Try to avoid doing anything (for performance).
  HGLRC current = wglGetCurrentContext();
  if (this->ContextId != current)
    {
    if(this->IsPicking && current)
      {
      vtkErrorMacro("Attempting to call MakeCurrent for a different window"
                    " than the one doing the picking, this can causes crashes"
                    " and/or bad pick results");
      }
    else
      {
      if (wglMakeCurrent(this->DeviceContext, this->ContextId) != TRUE)
        {
        LPVOID lpMsgBuf;
        ::FormatMessage(
          FORMAT_MESSAGE_ALLOCATE_BUFFER |
          FORMAT_MESSAGE_FROM_SYSTEM |
          FORMAT_MESSAGE_IGNORE_INSERTS,
          NULL,
          GetLastError(),
          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
          (LPTSTR) &lpMsgBuf,
          0,
          NULL
          );
        if(lpMsgBuf)
          {
#ifdef UNICODE
          wchar_t *wmsg = new wchar_t [mbstowcs(NULL, (const char*)lpMsgBuf, 32000)+1];
          wchar_t *wtemp = new wchar_t [mbstowcs(NULL, "wglMakeCurrent failed in MakeCurrent(), error: ", 32000)+1];
          mbstowcs(wmsg, (const char*)lpMsgBuf, 32000);
          mbstowcs(wtemp, "wglMakeCurrent failed in MakeCurrent(), error: ", 32000);
          vtkErrorMacro(<< wcscat(wtemp, wmsg));
          delete [] wmsg;
          delete [] wtemp;
#else
          vtkErrorMacro("wglMakeCurrent failed in MakeCurrent(), error: "
                        << (LPCTSTR)lpMsgBuf);
#endif
          ::LocalFree( lpMsgBuf );
          }
        }
      }
    }
}

// ----------------------------------------------------------------------------
// Description:
// Tells if this window is the current OpenGL context for the calling thread.
Ken Martin's avatar
Ken Martin committed
253
bool vtkWin32OpenGLRenderWindow::IsCurrent()
Ken Martin's avatar
Ken Martin committed
254
255
256
257
{
  return this->ContextId!=0 && this->ContextId==wglGetCurrentContext();
}

258
// ----------------------------------------------------------------------------
259
void AdjustWindowRectForBorders(HWND hwnd, DWORD style, const int x, const int y,
260
261
                                const int width, const int height, RECT &r)
{
262
  if (!style && hwnd)
263
    {
264
    style = GetWindowLong(hwnd, GWL_STYLE);
265
266
267
268
269
270
271
272
273
274
275
276
277
    }
  r.left = x;
  r.top = y;
  r.right = r.left + width;
  r.bottom = r.top + height;
  BOOL result = AdjustWindowRect(&r, style, FALSE);
  if (!result)
    {
    vtkGenericWarningMacro("AdjustWindowRect failed, error: "
      << GetLastError());
    }
}

Ken Martin's avatar
Ken Martin committed
278
// ----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
279
void vtkWin32OpenGLRenderWindow::SetSize(int x, int y)
Ken Martin's avatar
Ken Martin committed
280
281
282
283
{
  static int resizing = 0;
  if ((this->Size[0] != x) || (this->Size[1] != y))
    {
284
    this->Superclass::SetSize(x, y);
Ken Martin's avatar
Ken Martin committed
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312

    if (this->Interactor)
      {
      this->Interactor->SetSize(x, y);
      }

    if (this->OffScreenRendering)
      {
      if(!this->CreatingOffScreenWindow)
        {
        if (!resizing)
          {
          resizing = 1;
          this->CleanUpOffScreenRendering();
          this->CreateOffScreenWindow(x,y);
          resizing = 0;
          }
        }
      }

    else if (this->Mapped)
      {
      if (!resizing)
        {
        resizing = 1;

        if (this->ParentId)
          {
313
314
315
          SetWindowExtEx(this->DeviceContext, x, y, NULL);
          SetViewportExtEx(this->DeviceContext, x, y, NULL);
          SetWindowPos(this->WindowId, HWND_TOP, 0, 0,
Ken Martin's avatar
Ken Martin committed
316
317
318
319
                       x, y, SWP_NOMOVE | SWP_NOZORDER);
          }
        else
          {
320
          RECT r;
321
          AdjustWindowRectForBorders(this->WindowId, 0, 0, 0, x, y, r);
322
323
324
          SetWindowPos(this->WindowId, HWND_TOP, 0, 0,
                       r.right - r.left,
                       r.bottom - r.top,
Ken Martin's avatar
Ken Martin committed
325
326
327
328
329
330
331
332
                       SWP_NOMOVE | SWP_NOZORDER);
          }
        resizing = 0;
        }
      }
    }
}

Ken Martin's avatar
Ken Martin committed
333
void vtkWin32OpenGLRenderWindow::SetPosition(int x, int y)
Ken Martin's avatar
Ken Martin committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
{
  static int resizing = 0;

  if ((this->Position[0] != x) || (this->Position[1] != y))
    {
    this->Modified();
    this->Position[0] = x;
    this->Position[1] = y;
    if (this->Mapped)
      {
      if (!resizing)
        {
        resizing = 1;

        SetWindowPos(this->WindowId,HWND_TOP,x,y,
                     0, 0, SWP_NOSIZE | SWP_NOZORDER);
        resizing = 0;
        }
      }
    }
}


// End the rendering process and display the image.
Ken Martin's avatar
Ken Martin committed
358
void vtkWin32OpenGLRenderWindow::Frame(void)
Ken Martin's avatar
Ken Martin committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
{
  this->MakeCurrent();
  if (!this->AbortRender && this->DoubleBuffer && this->SwapBuffers)
    {
    // If this check is not enforced, we crash in offscreen rendering
    if (this->DeviceContext)
      {
      // use global scope to get Win32 API SwapBuffers and not be
      // confused with this->SwapBuffers
      ::SwapBuffers(this->DeviceContext);
      vtkDebugMacro(<< " SwapBuffers\n");
      }
    }
}

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
void vtkWin32OpenGLRenderWindow::VTKRegisterClass()
{
  // has the class been registered ?
  WNDCLASS wndClass;
#ifdef UNICODE
  if (!GetClassInfo(this->ApplicationInstance,L"vtkOpenGL",&wndClass))
#else
  if (!GetClassInfo(this->ApplicationInstance,"vtkOpenGL",&wndClass))
#endif
    {
    wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS;
    wndClass.lpfnWndProc = vtkWin32OpenGLRenderWindow::WndProc;
    wndClass.cbClsExtra = 0;
    wndClass.hInstance = this->ApplicationInstance;
    wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wndClass.lpszMenuName = NULL;
#ifdef UNICODE
    wndClass.lpszClassName = L"vtkOpenGL";
#else
    wndClass.lpszClassName = "vtkOpenGL";
#endif
    // vtk doesn't use the first extra vtkLONG's worth of bytes,
    // but app writers may want them, so we provide them. VTK
    // does use the second vtkLONG's worth of bytes of extra space.
    wndClass.cbWndExtra = 2 * sizeof(vtkLONG);
    RegisterClass(&wndClass);
    }
}

Ken Martin's avatar
Ken Martin committed
405
int vtkWin32OpenGLRenderWindow::SupportsOpenGL()
Ken Martin's avatar
Ken Martin committed
406
{
407
408
409
410
  if (this->OpenGLSupportTested)
    {
    return this->OpenGLSupportResult;
    }
411

412
413
414
415
416
  vtkOutputWindow *oldOW = vtkOutputWindow::GetInstance();
  oldOW->Register(this);
  vtkNew<vtkStringOutputWindow> sow;
  vtkOutputWindow::SetInstance(sow.Get());

417
418
419
420
  vtkWin32OpenGLRenderWindow *rw = vtkWin32OpenGLRenderWindow::New();
  rw->SetOffScreenRendering(1);
  rw->Initialize();
  if (rw->GetContextSupportsOpenGL32())
Ken Martin's avatar
Ken Martin committed
421
    {
422
423
424
    this->OpenGLSupportResult = 1;
    this->OpenGLSupportMessage =
      "The system appears to support OpenGL 3.2";
Ken Martin's avatar
Ken Martin committed
425
426
    }

427
428
429
#ifdef GLEW_OK

  else if (GLEW_VERSION_3_2 || (GLEW_VERSION_2_1 && GLEW_EXT_gpu_shader4))
430
    {
431
432
433
    this->OpenGLSupportResult = 1;
    this->OpenGLSupportMessage =
      "The system appears to support OpenGL 3.2 or has 2.1 with the required extension";
434
    }
Ken Martin's avatar
Ken Martin committed
435

436
#endif
Ken Martin's avatar
Ken Martin committed
437

438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
  if (this->OpenGLSupportResult)
    {
    // even if glew thinks we have support we should actually try linking a
    // shader program to make sure
    vtkShaderProgram *newShader =
      rw->GetShaderCache()->ReadyShaderProgram(
        // simple vert shader
        "//VTK::System::Dec\n"
        "attribute vec4 vertexMC;\n"
        "void main() { gl_Position = vertexMC; }\n",
        // frag shader that used gl_PrimitiveId
        "//VTK::System::Dec\n"
        "//VTK::Output::Dec\n"
        "void main(void) {\n"
        "  gl_FragData[0] = vec4(float(gl_PrimitiveID)/100.0,1.0,1.0,1.0);\n"
        "}\n",
        // no geom shader
        "");
    if (newShader == NULL)
      {
      this->OpenGLSupportResult = 0;
      this->OpenGLSupportMessage =
        "The system appeared to have OpenGL Support but a test shader program failed to compile and link";
      }
    }

  rw->Delete();

466
467
468
469
470
471
  this->OpenGLSupportMessage +=
    "vtkOutputWindow Text Folows:\n\n" +
    sow->GetOutput();
  vtkOutputWindow::SetInstance(oldOW);
  oldOW->Delete();

472
473
474
  this->OpenGLSupportTested = true;

  return this->OpenGLSupportResult;
Ken Martin's avatar
Ken Martin committed
475
476
477
}


Ken Martin's avatar
Ken Martin committed
478
int vtkWin32OpenGLRenderWindow::IsDirect()
Ken Martin's avatar
Ken Martin committed
479
{
480
  this->MakeCurrent();
Ken Martin's avatar
Ken Martin committed
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
  if (!this->DeviceContext)
    {
    return 0;
    }

  int pixelFormat = GetPixelFormat(this->DeviceContext);
  PIXELFORMATDESCRIPTOR pfd;

  DescribePixelFormat(this->DeviceContext, pixelFormat,
                      sizeof(PIXELFORMATDESCRIPTOR), &pfd);

  return (pfd.dwFlags & PFD_GENERIC_FORMAT) ? 0:1;

}


Ken Martin's avatar
Ken Martin committed
497
const char* vtkWin32OpenGLRenderWindow::ReportCapabilities()
Ken Martin's avatar
Ken Martin committed
498
{
499
  this->MakeCurrent();
Ken Martin's avatar
Ken Martin committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515

  if (!this->DeviceContext)
    {
    return "no device context";
    }

  int pixelFormat = GetPixelFormat(this->DeviceContext);
  PIXELFORMATDESCRIPTOR pfd;

  DescribePixelFormat(this->DeviceContext, pixelFormat,
                      sizeof(PIXELFORMATDESCRIPTOR), &pfd);

  const char *glVendor = (const char *) glGetString(GL_VENDOR);
  const char *glRenderer = (const char *) glGetString(GL_RENDERER);
  const char *glVersion = (const char *) glGetString(GL_VERSION);

516
517
518
519
520
521
522
523
std::ostringstream strm;
  if(glVendor)
    strm << "OpenGL vendor string:  " << glVendor << endl;
  if(glRenderer)
    strm << "OpenGL renderer string:  " << glRenderer << endl;
  if(glVersion)
    strm << "OpenGL version string:  " << glVersion << endl;

524
525
526
527
528
529
530
531
  strm << "OpenGL extensions:  " << endl;
  GLint n, i;
  glGetIntegerv(GL_NUM_EXTENSIONS, &n);
  for (i = 0; i < n; i++)
    {
    const char *ext = (const char *)glGetStringi(GL_EXTENSIONS, i);
    strm << "  " << ext << endl;
    }
Ken Martin's avatar
Ken Martin committed
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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  strm << "PixelFormat Descriptor:" << endl;
  strm << "depth:  " << static_cast<int>(pfd.cDepthBits) << endl;
  if (pfd.cColorBits <= 8)
    {
    strm << "class:  PseudoColor" << endl;
    }
  else
    {
    strm << "class:  TrueColor" << endl;
    }
  strm << "buffer size:  " << static_cast<int>(pfd.cColorBits) << endl;
  strm << "level:  " << static_cast<int>(pfd.bReserved) << endl;
  if (pfd.iPixelType == PFD_TYPE_RGBA)
    {
    strm << "renderType:  rgba" << endl;
    }
  else
    {
    strm <<"renderType:  ci" << endl;
    }
  if (pfd.dwFlags & PFD_DOUBLEBUFFER) {
  strm << "double buffer:  True" << endl;
  } else {
  strm << "double buffer:  False" << endl;
  }
  if (pfd.dwFlags & PFD_STEREO) {
  strm << "stereo:  True" << endl;
  } else {
  strm << "stereo:  False" << endl;
  }
  if (pfd.dwFlags & PFD_GENERIC_FORMAT) {
  strm << "hardware acceleration:  False" << endl;
  } else {
  strm << "hardware acceleration:  True" << endl;
  }
  strm << "rgba:  redSize=" << static_cast<int>(pfd.cRedBits) << " greenSize=" << static_cast<int>(pfd.cGreenBits) << "blueSize=" << static_cast<int>(pfd.cBlueBits) << "alphaSize=" << static_cast<int>(pfd.cAlphaBits) << endl;
  strm << "aux buffers:  " << static_cast<int>(pfd.cAuxBuffers)<< endl;
  strm << "depth size:  " << static_cast<int>(pfd.cDepthBits) << endl;
  strm << "stencil size:  " << static_cast<int>(pfd.cStencilBits) << endl;
  strm << "accum:  redSize=" << static_cast<int>(pfd.cAccumRedBits) << " greenSize=" << static_cast<int>(pfd.cAccumGreenBits) << "blueSize=" << static_cast<int>(pfd.cAccumBlueBits) << "alphaSize=" << static_cast<int>(pfd.cAccumAlphaBits) << endl;

  delete[] this->Capabilities;

  size_t len = strm.str().length() + 1;
  this->Capabilities = new char[len];
  strncpy(this->Capabilities, strm.str().c_str(), len);

  return this->Capabilities;
}

typedef bool (APIENTRY *wglChoosePixelFormatARBType)(HDC, const int*, const float*, unsigned int, int*, unsigned int*);

Ken Martin's avatar
Ken Martin committed
584
585
586
587
void vtkWin32OpenGLRenderWindow::SetupPixelFormatPaletteAndContext(
  HDC hDC, DWORD dwFlags,
  int debug, int bpp,
  int zbpp)
Ken Martin's avatar
Ken Martin committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
{
  // Create a dummy window, needed for calling wglGetProcAddress.
#ifdef UNICODE
  HWND tempId = CreateWindow(L"vtkOpenGL", 0, 0, 0, 0, 1, 1, 0, 0, this->ApplicationInstance, 0);
#else
  HWND tempId = CreateWindow("vtkOpenGL", 0, 0, 0, 0, 1, 1, 0, 0, this->ApplicationInstance, 0);
#endif
  HDC tempDC = GetDC(tempId);
  PIXELFORMATDESCRIPTOR tempPfd;
  memset(&tempPfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
  tempPfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  tempPfd.nVersion = 1;
  tempPfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
  tempPfd.iPixelType = PFD_TYPE_RGBA;
  int tempPixelFormat = ChoosePixelFormat(tempDC, &tempPfd);
603
  SetPixelFormat(tempDC, tempPixelFormat, &tempPfd);
Ken Martin's avatar
Ken Martin committed
604
605
606
  HGLRC tempContext = wglCreateContext(tempDC);
  wglMakeCurrent(tempDC, tempContext);

Ken Martin's avatar
Ken Martin committed
607
608
609
  // make sure glew is initialized with fake window
  this->OpenGLInit();

Ken Martin's avatar
Ken Martin committed
610
611
  // First we try to use the newer wglChoosePixelFormatARB which enables
  // features like multisamples.
612
  PIXELFORMATDESCRIPTOR pfd;
Ken Martin's avatar
Ken Martin committed
613
  int pixelFormat = 0;
614
  if (wglChoosePixelFormatARB)
Ken Martin's avatar
Ken Martin committed
615
616
    {
    int attrib[] = {
Ken Martin's avatar
Ken Martin committed
617
618
619
620
621
622
623
      WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
      WGL_SUPPORT_OPENGL_ARB, TRUE,
      WGL_DRAW_TO_WINDOW_ARB, TRUE,
      WGL_DOUBLE_BUFFER_ARB, TRUE,
      WGL_COLOR_BITS_ARB, bpp/4*3,
      WGL_DEPTH_BITS_ARB, zbpp/4*3,
      WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
Ken Martin's avatar
Ken Martin committed
624
625
626
627
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    unsigned int n = 14;
    if (this->AlphaBitPlanes)
      {
Ken Martin's avatar
Ken Martin committed
628
      attrib[n] = WGL_ALPHA_BITS_ARB;
Ken Martin's avatar
Ken Martin committed
629
630
631
632
633
      attrib[n+1] = bpp/4;
      n += 2;
      }
    if (this->StencilCapable)
      {
Ken Martin's avatar
Ken Martin committed
634
      attrib[n] = WGL_STENCIL_BITS_ARB;
Ken Martin's avatar
Ken Martin committed
635
636
637
      attrib[n+1] = 8;
      n += 2;
      }
638
    unsigned int stereoAttributeIndex = 0;
Ken Martin's avatar
Ken Martin committed
639
640
    if (dwFlags & PFD_STEREO)
      {
Ken Martin's avatar
Ken Martin committed
641
      attrib[n] = WGL_STEREO_ARB;
Ken Martin's avatar
Ken Martin committed
642
      attrib[n+1] = TRUE;
643
      stereoAttributeIndex = n+1;
Ken Martin's avatar
Ken Martin committed
644
645
646
      n += 2;
      }
    unsigned int multiSampleAttributeIndex = 0;
Ken Martin's avatar
Ken Martin committed
647
648
    if (this->MultiSamples > 1 &&
        wglewIsSupported("WGL_ARB_multisample"))
Ken Martin's avatar
Ken Martin committed
649
      {
Ken Martin's avatar
Ken Martin committed
650
      attrib[n] = WGL_SAMPLE_BUFFERS_ARB;
Ken Martin's avatar
Ken Martin committed
651
      attrib[n+1] = 1;
Ken Martin's avatar
Ken Martin committed
652
      attrib[n+2] = WGL_SAMPLES_ARB;
Ken Martin's avatar
Ken Martin committed
653
654
655
656
657
      attrib[n+3] = this->MultiSamples;
      multiSampleAttributeIndex = n+3;
      n += 4;
      }
    unsigned int numFormats;
658
659
    if (!wglChoosePixelFormatARB(hDC, attrib, 0, 1, &pixelFormat, &numFormats)
      || numFormats == 0)
Ken Martin's avatar
Ken Martin committed
660
661
662
663
664
665
      {
      // If the requested number of multisamples does not work, try
      // scaling down the number of multisamples a few times.
      if (multiSampleAttributeIndex)
        {
        attrib[multiSampleAttributeIndex] /= 2;
666
667
        if (!wglChoosePixelFormatARB(hDC, attrib, 0, 1,
              &pixelFormat, &numFormats) || numFormats == 0)
Ken Martin's avatar
Ken Martin committed
668
669
670
671
672
          {
          attrib[multiSampleAttributeIndex] /= 2;
          wglChoosePixelFormatARB(hDC, attrib, 0, 1, &pixelFormat, &numFormats);
          }
        }
673
674
675
676
677
678
      // try dropping stereo
      if (stereoAttributeIndex && numFormats == 0)
        {
        attrib[stereoAttributeIndex] = FALSE;
        wglChoosePixelFormatARB(hDC, attrib, 0, 1, &pixelFormat, &numFormats);
        }
Ken Martin's avatar
Ken Martin committed
679
      }
680

Ken Martin's avatar
Ken Martin committed
681
682
683
684
685
    DescribePixelFormat(hDC, pixelFormat, sizeof(pfd), &pfd);
    if (!SetPixelFormat(hDC, pixelFormat, &pfd))
      {
      pixelFormat = 0;
      }
Ken Martin's avatar
Ken Martin committed
686
687
688
689
690
691
692
693
    else
      {
      if (debug && (dwFlags & PFD_STEREO) && !(pfd.dwFlags & PFD_STEREO))
        {
        vtkGenericWarningMacro("No Stereo Available!");
        this->StereoCapableWindow = 0;
        }
      }
Ken Martin's avatar
Ken Martin committed
694
    }
695
696
697
698
  else
    {
    vtkErrorMacro("failed to get wglChoosePixelFormatARB");
    }
Ken Martin's avatar
Ken Martin committed
699

700
  // see if we can get a 3.2 context
Ken Martin's avatar
Ken Martin committed
701
702
703
704
705
  if (pixelFormat)
    {
    this->SetupPalette(hDC);

    // create a context
706
707
708
709
    PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB =
      reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
    if (wglCreateContextAttribsARB)
      {
710
711
712
713
714
      this->ContextId = 0;
      // we believe that these later versions are all compatible with
      // OpenGL 3.2 so get a more recent context if we can.
      int attemptedVersions[] = {4,5, 4,4, 4,3, 4,2, 4,1, 4,0, 3,3, 3,2};
      for (int i = 0; i < 8 && !this->ContextId; i++)
715
        {
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
        int iContextAttribs[] =
          {
          WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
          WGL_CONTEXT_MINOR_VERSION_ARB, 2,
          WGL_CONTEXT_FLAGS_ARB, 0,
          // WGL_CONTEXT_PROFILE_MASK_ARB,
          // WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
          // WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
          0 // End of attributes list
          };
        iContextAttribs[1] = attemptedVersions[i*2];
        iContextAttribs[3] = attemptedVersions[i*2+1];

        this->ContextId = wglCreateContextAttribsARB(hDC, 0, iContextAttribs);
        }
731
732
733
734
735
736
737
      }
    if (this->ContextId)
      {
      this->SetContextSupportsOpenGL32(true);
      }
    else
      {
Ken Martin's avatar
Ken Martin committed
738
      this->ContextId = wglCreateContext(hDC);
739
      }
Ken Martin's avatar
Ken Martin committed
740
741
742
743
744
745
    if (this->ContextId == NULL)
      {
      vtkErrorMacro("wglCreateContext failed in CreateAWindow(), error: " << GetLastError());
      }
    }

Ken Martin's avatar
Ken Martin committed
746
747
748
749
750
751
752
  // Delete the dummy window
  wglMakeCurrent(tempDC, 0);
  wglDeleteContext(tempContext);
  ReleaseDC(tempId, tempDC);
  ::DestroyWindow(tempId); // windows api

  // If we got a valid pixel format in the process, we are done.
753
754
  // Otherwise fail as the OpenGL does not support even 2.1
  if (!pixelFormat)
Ken Martin's avatar
Ken Martin committed
755
    {
756
    vtkErrorMacro("failed to get valid pixel format.");
Ken Martin's avatar
Ken Martin committed
757
758
    }

759
  return;
Ken Martin's avatar
Ken Martin committed
760
761
}

Ken Martin's avatar
Ken Martin committed
762
void vtkWin32OpenGLRenderWindow::SetupPalette(HDC hDC)
Ken Martin's avatar
Ken Martin committed
763
764
765
766
767
768
769
770
{
  int pixelFormat = GetPixelFormat(hDC);
  PIXELFORMATDESCRIPTOR pfd;
  LOGPALETTE* pPal;
  int paletteSize;

  DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

Ken Martin's avatar
Ken Martin committed
771
772
773
774
775
776
777
778
  if (pfd.dwFlags & PFD_NEED_PALETTE)
    {
    paletteSize = 1 << pfd.cColorBits;
    }
  else
    {
    return;
    }
Ken Martin's avatar
Ken Martin committed
779
780
781
782
783
784
785
786
787
788
789
790
791

  pPal = (LOGPALETTE*)
    malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
  pPal->palVersion = 0x300;
  pPal->palNumEntries = paletteSize;

  /* build a simple RGB color palette */
  {
  int redMask = (1 << pfd.cRedBits) - 1;
  int greenMask = (1 << pfd.cGreenBits) - 1;
  int blueMask = (1 << pfd.cBlueBits) - 1;
  int i;

Ken Martin's avatar
Ken Martin committed
792
793
794
795
796
797
798
799
800
801
  for (i=0; i<paletteSize; ++i)
    {
    pPal->palPalEntry[i].peRed =
      (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
    pPal->palPalEntry[i].peGreen =
      (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
    pPal->palPalEntry[i].peBlue =
      (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
    pPal->palPalEntry[i].peFlags = 0;
    }
Ken Martin's avatar
Ken Martin committed
802
803
804
805
806
  }

  this->Palette = CreatePalette(pPal);
  free(pPal);

Ken Martin's avatar
Ken Martin committed
807
808
809
810
811
  if (this->Palette)
    {
    this->OldPalette = SelectPalette(hDC, this->Palette, FALSE);
    RealizePalette(hDC);
    }
Ken Martin's avatar
Ken Martin committed
812
813
814
}


Ken Martin's avatar
Ken Martin committed
815
LRESULT vtkWin32OpenGLRenderWindow::MessageProc(HWND hWnd, UINT message,
Ken Martin's avatar
Ken Martin committed
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
                                                WPARAM wParam, LPARAM lParam)
{
  switch (message)
    {
    case WM_CREATE:
    {
    // nothing to be done here, opengl is initilized after the call to
    // create now
    return 0;
    }
    case WM_DESTROY:
      this->Clean();
      if (this->DeviceContext)
        {
        ReleaseDC(this->WindowId, this->DeviceContext);
        this->DeviceContext = NULL;
        this->WindowId = NULL;
        }
      return 0;
    case WM_SIZE:
      /* track window size changes */
      if (this->ContextId)
        {
        this->SetSize((int) LOWORD(lParam),(int) HIWORD(lParam));
        return 0;
        }
    case WM_PALETTECHANGED:
      /* realize palette if this is *not* the current window */
      if (this->ContextId && this->Palette && (HWND) wParam != hWnd)
        {
        SelectPalette(this->DeviceContext, this->OldPalette, FALSE);
        UnrealizeObject(this->Palette);
        this->OldPalette = SelectPalette(this->DeviceContext,
                                         this->Palette, FALSE);
        RealizePalette(this->DeviceContext);
        this->Render();
        }
      break;
    case WM_QUERYNEWPALETTE:
      /* realize palette if this is the current window */
      if (this->ContextId && this->Palette)
        {
        SelectPalette(this->DeviceContext, this->OldPalette, FALSE);
        UnrealizeObject(this->Palette);
        this->OldPalette = SelectPalette(this->DeviceContext,
                                         this->Palette, FALSE);
        RealizePalette(this->DeviceContext);
        this->Render();
        return TRUE;
        }
      break;
    case WM_PAINT:
    {
    PAINTSTRUCT ps;
    BeginPaint(hWnd, &ps);
    if (this->ContextId)
      {
      this->Render();
      }
    EndPaint(hWnd, &ps);
    return 0;
    }
    break;
    case WM_ERASEBKGND:
      return TRUE;
    case WM_SETCURSOR:
      if (HTCLIENT == LOWORD(lParam))
        {
        this->SetCurrentCursor(this->GetCurrentCursor());
        return TRUE;
        }
      break;
    default:
      this->InvokeEvent(vtkCommand::RenderWindowMessageEvent, &message);
      break;
    }
  return DefWindowProc(hWnd, message, wParam, lParam);
}


Ken Martin's avatar
Ken Martin committed
896
void vtkWin32OpenGLRenderWindow::InitializeApplication()
Ken Martin's avatar
Ken Martin committed
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
{
  // get the application instance if we don't have one already
  if (!this->ApplicationInstance)
    {
    // if we have a parent window get the app instance from it
    if (this->ParentId)
      {
      this->ApplicationInstance = (HINSTANCE)vtkGetWindowLong(this->ParentId,vtkGWL_HINSTANCE);
      }
    else
      {
      this->ApplicationInstance = GetModuleHandle(NULL); /*AfxGetInstanceHandle();*/
      }
    }
}

Ken Martin's avatar
Ken Martin committed
913
void vtkWin32OpenGLRenderWindow::CreateAWindow()
Ken Martin's avatar
Ken Martin committed
914
{
915
  this->VTKRegisterClass();
Ken Martin's avatar
Ken Martin committed
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971

  if(this->WindowIdReferenceCount == 0)
    {
    static int count = 1;
    char *windowName;

    if (!this->WindowId)
      {
      this->DeviceContext = 0;

      int len = static_cast<int>(strlen("Visualization Toolkit - Win32OpenGL #"))
        + (int)ceil( (double) log10( (double)(count+1) ) )
        + 1;
      windowName = new char [ len ];
      sprintf(windowName,"Visualization Toolkit - Win32OpenGL #%i",count++);
      this->SetWindowName(windowName);
      delete [] windowName;

#ifdef UNICODE
      wchar_t *wname = new wchar_t [mbstowcs(NULL, this->WindowName, 32000)+1];
      mbstowcs(wname, this->WindowName, 32000);
#endif
      int x = ((this->Position[0] >= 0) ? this->Position[0] : 5);
      int y = ((this->Position[1] >= 0) ? this->Position[1] : 5);
      int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
      int width = ((this->Size[0] > 0) ? this->Size[0] : 300);

      /* create window */
      if (this->ParentId)
        {
#ifdef UNICODE
        this->WindowId = CreateWindow(
          L"vtkOpenGL", wname,
          WS_CHILD | WS_CLIPCHILDREN /*| WS_CLIPSIBLINGS*/,
          x, y, width, height,
          this->ParentId, NULL, this->ApplicationInstance, NULL);
#else
        this->WindowId = CreateWindow(
          "vtkOpenGL", this->WindowName,
          WS_CHILD | WS_CLIPCHILDREN /*| WS_CLIPSIBLINGS*/,
          x, y, width, height,
          this->ParentId, NULL, this->ApplicationInstance, NULL);
#endif
        }
      else
        {
        DWORD style;
        if (this->Borders)
          {
          style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN /*| WS_CLIPSIBLINGS*/;
          }
        else
          {
          style = WS_POPUP | WS_CLIPCHILDREN /*| WS_CLIPSIBLINGS*/;
          }
        RECT r;
972
        AdjustWindowRectForBorders(0, style, x, y, width, height, r);
Ken Martin's avatar
Ken Martin committed
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
#ifdef UNICODE
        this->WindowId = CreateWindow(
          L"vtkOpenGL", wname, style,
          x, y, r.right-r.left, r.bottom-r.top,
          NULL, NULL, this->ApplicationInstance, NULL);
#else
        this->WindowId = CreateWindow(
          "vtkOpenGL", this->WindowName, style,
          x, y, r.right-r.left, r.bottom-r.top,
          NULL, NULL, this->ApplicationInstance, NULL);
#endif
        }
#ifdef UNICODE
      delete [] wname;
#endif

      if (!this->WindowId)
        {
        vtkErrorMacro("Could not create window, error:  " << GetLastError());
        return;
        }
      // extract the create info

      /* display window */
      if(!this->OffScreenRendering)
        {
        ShowWindow(this->WindowId, SW_SHOW);
        }
      //UpdateWindow(this->WindowId);
      this->OwnWindow = 1;
      vtkSetWindowLong(this->WindowId,sizeof(vtkLONG),(intptr_t)this);
      }
    if (!this->DeviceContext)
      {
      this->DeviceContext = GetDC(this->WindowId);
      }
    if (this->StereoCapableWindow)
      {
Ken Martin's avatar
Ken Martin committed
1011
      this->SetupPixelFormatPaletteAndContext(this->DeviceContext, PFD_SUPPORT_OPENGL |
Ken Martin's avatar
Ken Martin committed
1012
1013
1014
1015
1016
                             PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER |
                             PFD_STEREO, this->GetDebug(), 32, 32);
      }
    else
      {
Ken Martin's avatar
Ken Martin committed
1017
      this->SetupPixelFormatPaletteAndContext(this->DeviceContext, PFD_SUPPORT_OPENGL |
Ken Martin's avatar
Ken Martin committed
1018
1019
1020
1021
1022
1023
                             PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
                             this->GetDebug(), 32, 32);
      }
    this->MakeCurrent();

    // wipe out any existing display lists
1024
    this->ReleaseGraphicsResources(this);
Ken Martin's avatar
Ken Martin committed
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
    this->OpenGLInit();
    this->Mapped = 1;
    this->WindowIdReferenceCount = 1;
    }
  else
    {
    ++this->WindowIdReferenceCount;
    }
}

// Initialize the window for rendering.
Ken Martin's avatar
Ken Martin committed
1036
void vtkWin32OpenGLRenderWindow::WindowInitialize()
Ken Martin's avatar
Ken Martin committed
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
{
  // create our own window if not already set
  this->OwnWindow = 0;
  if (!this->MFChandledWindow)
    {
    this->InitializeApplication();
    this->CreateAWindow();
    }
  else
    {
    this->MakeCurrent(); // hsr
    this->OpenGLInit();
    }
}

// Initialize the rendering window.
Ken Martin's avatar
Ken Martin committed
1053
void vtkWin32OpenGLRenderWindow::Initialize (void)
Ken Martin's avatar
Ken Martin committed
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
{
  // make sure we havent already been initialized
  if (!this->OffScreenRendering && !this->ContextId)
    {
    this->WindowInitialize();
    }
  else
    {
    if(this->OffScreenRendering && !(this->ContextId ||
                                     this->OffScreenUseFrameBuffer))
      {
      this->InitializeApplication();
      int width = ((this->Size[0] > 0) ? this->Size[0] : 300);
      int height = ((this->Size[1] > 0) ? this->Size[1] : 300);
      this->CreateOffScreenWindow(width,height);
      }
    }
}

Ken Martin's avatar
Ken Martin committed
1073
void vtkWin32OpenGLRenderWindow::Finalize (void)
Ken Martin's avatar
Ken Martin committed
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
{
  if (this->CursorHidden)
    {
    this->ShowCursor();
    }

  if (this->OffScreenRendering)
    {
    this->CleanUpOffScreenRendering();
    }
  this->DestroyWindow();
}

Ken Martin's avatar
Ken Martin committed
1087
void vtkWin32OpenGLRenderWindow::DestroyWindow()
Ken Martin's avatar
Ken Martin committed
1088
{
1089
  this->Clean();
Ken Martin's avatar
Ken Martin committed
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
  if(this->WindowIdReferenceCount > 0)
    {
    --this->WindowIdReferenceCount;
    if(this->WindowIdReferenceCount == 0)
      {
      if (this->WindowId)
        {
        ReleaseDC(this->WindowId, this->DeviceContext);
        // can't set WindowId=NULL, needed for DestroyWindow
        this->DeviceContext = NULL;

        // clear the extra data before calling destroy
        vtkSetWindowLong(this->WindowId,sizeof(vtkLONG),(vtkLONG)0);
        if(this->OwnWindow)
          {
          ::DestroyWindow(this->WindowId); // windows api
          this->WindowId=0;
          }
        }
      }
    }
}

// Get the current size of the window.
Ken Martin's avatar
Ken Martin committed
1114
int *vtkWin32OpenGLRenderWindow::GetSize(void)
Ken Martin's avatar
Ken Martin committed
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
{
  // if we aren't mapped then just return the ivar
  if (this->Mapped)
    {
    RECT rect;

    //  Find the current window size
    if (GetClientRect(this->WindowId, &rect))
      {
      this->Size[0] = rect.right;
      this->Size[1] = rect.bottom;
      }
    else
      {
      this->Size[0] = 0;
      this->Size[1] = 0;
      }

    }

1135
  return this->vtkOpenGLRenderWindow::GetSize();
Ken Martin's avatar
Ken Martin committed
1136
1137
}

1138
// Get the size of the whole screen.
Ken Martin's avatar
Ken Martin committed
1139
int *vtkWin32OpenGLRenderWindow::GetScreenSize(void)
Ken Martin's avatar
Ken Martin committed
1140
{
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
  HDC hDC = ::GetDC(NULL);
  if (hDC)
    {
    // This technique yields the screen size of the primary monitor
    // only in a multi-monitor configuration...
    this->Size[0] = ::GetDeviceCaps(hDC, HORZRES);
    this->Size[1] = ::GetDeviceCaps(hDC, VERTRES);
    ::ReleaseDC(NULL, hDC);
    }
  else
    {
    // This technique gets the "work area" (the whole screen except
    // for the bit covered by the Windows task bar) -- use it as a
    // fallback if there's an error calling GetDC.
    RECT rect;
    SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
Ken Martin's avatar
Ken Martin committed
1157

1158
1159
1160
    this->Size[0] = rect.right - rect.left;
    this->Size[1] = rect.bottom - rect.top;
    }
Ken Martin's avatar
Ken Martin committed
1161
1162
1163
1164
1165

  return this->Size;
}

// Get the position in screen coordinates of the window.
Ken Martin's avatar
Ken Martin committed
1166
int *vtkWin32OpenGLRenderWindow::GetPosition(void)
Ken Martin's avatar
Ken Martin committed
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
{
  // if we aren't mapped then just return the ivar
  if (!this->Mapped)
    {
    return this->Position;
    }

  //  Find the current window position
  //  x,y,&this->Position[0],&this->Position[1],&child);

  return this->Position;
}

// Change the window to fill the entire screen.
Ken Martin's avatar
Ken Martin committed
1181
void vtkWin32OpenGLRenderWindow::SetFullScreen(int arg)
Ken Martin's avatar
Ken Martin committed
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
{
  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)
      {
      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();

  this->Modified();
}

//
// Set the variable that indicates that we want a stereo capable window
// be created. This method can only be called before a window is realized.
//
Ken Martin's avatar
Ken Martin committed
1230
void vtkWin32OpenGLRenderWindow::SetStereoCapableWindow(int capable)
Ken Martin's avatar
Ken Martin committed
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
{
  if (this->ContextId == 0)
    {
    vtkRenderWindow::SetStereoCapableWindow(capable);
    }
  else
    {
    vtkWarningMacro(<< "Requesting a StereoCapableWindow must be performed "
                    << "before the window is realized, i.e. before a render.");
    }
}


// Set the preferred window size to full screen.
Ken Martin's avatar
Ken Martin committed
1245
void vtkWin32OpenGLRenderWindow::PrefFullScreen()
Ken Martin's avatar
Ken Martin committed
1246
{
1247
  int *size = this->GetScreenSize();
Ken Martin's avatar
Ken Martin committed
1248

1249
1250
1251
1252
  // don't show borders
  this->Borders = 0;

  RECT r;
1253
  AdjustWindowRectForBorders(this->WindowId, 0, 0, 0, size[0], size[1], r);
Ken Martin's avatar
Ken Martin committed
1254
1255
1256
1257

  // use full screen
  this->Position[0] = 0;
  this->Position[1] = 0;
1258
1259
  this->Size[0] = r.right - r.left;
  this->Size[1] = r.bottom - r.top;
Ken Martin's avatar
Ken Martin committed
1260
1261
1262
}

// Remap the window.
Ken Martin's avatar
Ken Martin committed
1263
void vtkWin32OpenGLRenderWindow::WindowRemap()
Ken Martin's avatar
Ken Martin committed
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
{
  // close everything down
  this->Finalize();

  // set the default windowid
  this->WindowId = this->NextWindowId;
  this->NextWindowId = 0;

  // and set it up!
  this->Initialize();
}

Ken Martin's avatar
Ken Martin committed
1276
void vtkWin32OpenGLRenderWindow::PrintSelf(ostream& os, vtkIndent indent)
Ken Martin's avatar
Ken Martin committed
1277
1278
1279
1280
1281
1282
1283
1284
1285
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "ContextId: " << this->ContextId << "\n";
  os << indent << "Next Window Id: " << this->NextWindowId << "\n";
  os << indent << "Window Id: " << this->WindowId << "\n";
}

// Get the window id.
Ken Martin's avatar
Ken Martin committed
1286
HWND vtkWin32OpenGLRenderWindow::GetWindowId()
Ken Martin's avatar
Ken Martin committed
1287
1288
1289
1290
1291
1292
1293
{
  vtkDebugMacro(<< "Returning WindowId of " << this->WindowId << "\n");

  return this->WindowId;
}

// Set the window id to a pre-existing window.
Ken Martin's avatar
Ken Martin committed
1294
void vtkWin32OpenGLRenderWindow::SetWindowId(HWND arg)
Ken Martin's avatar
Ken Martin committed
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
{
  vtkDebugMacro(<< "Setting WindowId to " << arg << "\n");

  if (arg != this->WindowId)
    {
    this->WindowId = arg;
    if (this->ContextId)
      {
      wglDeleteContext(this->ContextId);
      }
    this->ContextId = 0;
    this->DeviceContext = 0;
    }
}

// Set this RenderWindow's X window id to a pre-existing window.
Ken Martin's avatar
Ken Martin committed
1311
void vtkWin32OpenGLRenderWindow::SetWindowInfo(char *info)
Ken Martin's avatar
Ken Martin committed
1312
1313
1314
1315
1316
1317
1318
1319
1320
{
  int tmp;

  sscanf(info,"%i",&tmp);

  this->WindowId = (HWND)tmp;
  vtkDebugMacro(<< "Setting WindowId to " << this->WindowId << "\n");
}

Ken Martin's avatar
Ken Martin committed
1321
void vtkWin32OpenGLRenderWindow::SetNextWindowInfo(char *info)
Ken Martin's avatar
Ken Martin committed
1322
1323
1324
1325
1326
1327
1328
1329
{
  int tmp;

  sscanf(info,"%i",&tmp);

  this->SetNextWindowId((HWND)tmp);
}

Ken Martin's avatar
Ken Martin committed
1330
void vtkWin32OpenGLRenderWindow::SetDisplayId(void * arg)
Ken Martin's avatar
Ken Martin committed
1331
1332
1333
1334
{
  this->DeviceContext = (HDC) arg;
}

Ken Martin's avatar
Ken Martin committed
1335
void vtkWin32OpenGLRenderWindow::SetContextId(HGLRC arg)
Ken Martin's avatar
Ken Martin committed
1336
1337
1338
1339
{
  this->ContextId = arg;
}

Ken Martin's avatar
Ken Martin committed
1340
void vtkWin32OpenGLRenderWindow::SetDeviceContext(HDC arg)
Ken Martin's avatar
Ken Martin committed
1341
1342
1343
1344
1345
1346
{
  this->DeviceContext = arg;
  this->MFChandledWindow = TRUE;
}

// Sets the HWND id of the window that WILL BE created.
Ken Martin's avatar
Ken Martin committed
1347
void vtkWin32OpenGLRenderWindow::SetParentInfo(char *info)
Ken Martin's avatar
Ken Martin committed
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
{
  int tmp;

  sscanf(info,"%i",&tmp);

  this->ParentId = (HWND)tmp;
  vtkDebugMacro(<< "Setting ParentId to " << this->ParentId << "\n");
}

// Set the window id to a pre-existing window.
Ken Martin's avatar
Ken Martin committed
1358
void vtkWin32OpenGLRenderWindow::SetParentId(HWND arg)
Ken Martin's avatar
Ken Martin committed
1359
1360
1361
1362
1363
1364
1365
{
  vtkDebugMacro(<< "Setting ParentId to " << arg << "\n");

  this->ParentId = arg;
}

// Set the window id of the new window once a WindowRemap is done.
Ken Martin's avatar
Ken Martin committed
1366
void vtkWin32OpenGLRenderWindow::SetNextWindowId(HWND arg)
Ken Martin's avatar
Ken Martin committed
1367
1368
1369
1370
1371
1372
{
  vtkDebugMacro(<< "Setting NextWindowId to " << arg << "\n");

  this->NextWindowId = arg;
}

Ken Martin's avatar
Ken Martin committed
1373
void vtkWin32OpenGLRenderWindow::SetNextWindowId(void *arg)
Ken Martin's avatar
Ken Martin committed
1374
1375
1376
1377
1378
{
  this->SetNextWindowId((HWND)arg);
}

// Begin the rendering process.
Ken Martin's avatar
Ken Martin committed
1379
void vtkWin32OpenGLRenderWindow::Start(void)
Ken Martin's avatar
Ken Martin committed
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
{
  // if the renderer has not been initialized, do so now
  if (!this->ContextId)
    {
    this->Initialize();
    }

  // set the current window
  this->MakeCurrent();
}


Ken Martin's avatar
Ken Martin committed
1392
void vtkWin32OpenGLRenderWindow::SetOffScreenRendering(int offscreen)
Ken Martin's avatar
Ken Martin committed
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
{
  if (offscreen == this->OffScreenRendering)
    {
    return;
    }

  this->vtkRenderWindow::SetOffScreenRendering(offscreen);

  if (offscreen)
    {
    int size[2];
    size[0] = (this->Size[0] > 0) ? this->Size[0] : 300;
    size[1] = (this->Size[1] > 0) ? this->Size[1] : 300;
    this->SaveScreenRendering();
    this->CreateOffScreenWindow(size[0],size[1]);
    }
  else
    {
    this->CleanUpOffScreenRendering();
    if (!this->WindowId)
      {
      this->WindowInitialize();
      this->OpenGLInit();
      if (this->Interactor)
        {
        this->Interactor->ReInitialize();
        }
      this->DoubleBuffer = 1;
      }
    else
      {
      this->ResumeScreenRendering();
      }
    }
}

Ken Martin's avatar
Ken Martin committed
1429
void vtkWin32OpenGLRenderWindow::SaveScreenRendering()
Ken Martin's avatar
Ken Martin committed
1430
1431
1432
1433
1434
1435
1436
1437
1438
{
  this->ScreenMapped = this->Mapped;
  this->ScreenWindowSize[0] = this->Size[0];
  this->ScreenWindowSize[1] = this->Size[1];
  this->ScreenDeviceContext = this->DeviceContext;
  this->ScreenDoubleBuffer = this->DoubleBuffer;
  this->ScreenContextId = this->ContextId;
}

Ken Martin's avatar
Ken Martin committed
1439
void vtkWin32OpenGLRenderWindow::CreateOffScreenWindow(int width,
Ken Martin's avatar
Ken Martin committed
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
                                                       int height)
{
  int status = this->CreatingOffScreenWindow;
  this->CreatingOffScreenWindow = 1;
  if(!this->CreateHardwareOffScreenWindow(width,height))
    {
#ifdef UNICODE
    HDC dc = CreateDC(L"DISPLAY", 0, 0, 0);
#else
    HDC dc = CreateDC("DISPLAY", 0, 0, 0);
#endif
    this->CreateOffScreenDC(width,height,dc);
    DeleteDC(dc);
    }
  this->CreatingOffScreenWindow = status;
}

Ken Martin's avatar
Ken Martin committed
1457
void vtkWin32OpenGLRenderWindow::CreateOffScreenDC(int xsize, int ysize,
Ken Martin's avatar
Ken Martin committed
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
                                                   HDC aHdc)
{
  int dataWidth = ((xsize*3+3)/4)*4;

  this->MemoryDataHeader.bmiHeader.biSize = 40;
  this->MemoryDataHeader.bmiHeader.biWidth = xsize;
  this->MemoryDataHeader.bmiHeader.biHeight = ysize;
  this->MemoryDataHeader.bmiHeader.biPlanes = 1;
  this->MemoryDataHeader.bmiHeader.biBitCount = 24;
  this->MemoryDataHeader.bmiHeader.biCompression = BI_RGB;
  this->MemoryDataHeader.bmiHeader.biClrUsed = 0;
  this->MemoryDataHeader.bmiHeader.biClrImportant = 0;
  this->MemoryDataHeader.bmiHeader.biSizeImage = dataWidth*ysize;
  this->MemoryDataHeader.bmiHeader.biXPelsPerMeter = 10000;
  this->MemoryDataHeader.bmiHeader.biYPelsPerMeter = 10000;

  HBITMAP dib = CreateDIBSection(aHdc,
                                 &this->MemoryDataHeader, DIB_RGB_COLORS,
                                 (void **)(&(this->MemoryData)),  NULL, 0);
  SIZE oldSize;
  SetBitmapDimensionEx(dib, xsize, ysize, &oldSize);
  // try using a DIBsection
  this->CreateOffScreenDC(dib, aHdc);
}

Ken Martin's avatar
Ken Martin committed
1483
void vtkWin32OpenGLRenderWindow::CreateOffScreenDC(HBITMAP hbmp, HDC aHdc)
Ken Martin's avatar
Ken Martin committed
1484
{
1485
1486
1487
  this->InitializeApplication();
  this->VTKRegisterClass();

Ken Martin's avatar
Ken Martin committed
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
  BITMAP bm;
  GetObject(hbmp, sizeof(BITMAP), &bm);

  this->MemoryBuffer = hbmp;

  // Create a compatible device context
  this->MemoryHdc = (HDC)CreateCompatibleDC(aHdc);

  // Put the bitmap into the device context
  SelectObject(this->MemoryHdc, this->MemoryBuffer);

1499
  this->ReleaseGraphicsResources(this);
Ken Martin's avatar
Ken Martin committed
1500
1501
1502
1503
1504
1505
1506
1507

  // adjust settings for renderwindow
  this->Mapped =0;
  this->Size[0] = bm.bmWidth;
  this->Size[1] = bm.bmHeight;

  this->DeviceContext = this->MemoryHdc;
  this->DoubleBuffer = 0;
Ken Martin's avatar
Ken Martin committed
1508
  this->SetupPixelFormatPaletteAndContext(this->DeviceContext,
Ken Martin's avatar
Ken Martin committed
1509
1510
1511
1512
1513
1514
                         PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI |
                         PFD_DRAW_TO_BITMAP, this->GetDebug(), 24, 32);
  this->MakeCurrent();
  this->OpenGLInit();
}

Ken Martin's avatar
Ken Martin committed
1515
void vtkWin32OpenGLRenderWindow::SetupMemoryRendering(int xsize, int ysize,
Ken Martin's avatar
Ken Martin committed
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
                                                      HDC aHdc)
{
  // save the current state
  this->ScreenMapped = this->Mapped;
  this->ScreenWindowSize[0] = this->Size[0];
  this->ScreenWindowSize[1] = this->Size[1];
  this->ScreenDeviceContext = this->DeviceContext;
  this->ScreenDoubleBuffer = this->DoubleBuffer;
  this->ScreenContextId = this->ContextId;

  this->CreateOffScreenDC(xsize, ysize, aHdc);
}

Ken Martin's avatar
Ken Martin committed
1529
void vtkWin32OpenGLRenderWindow::SetupMemoryRendering(HBITMAP hbmp)
Ken Martin's avatar
Ken Martin committed
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
{
#ifdef UNICODE
  HDC dc = CreateDC(L"DISPLAY", 0, 0, 0);
#else
  HDC dc = CreateDC("DISPLAY", 0, 0, 0);
#endif

  // save the current state
  this->ScreenMapped = this->Mapped;
  this->ScreenWindowSize[0] = this->Size[0];
  this->ScreenWindowSize[1] = this->Size[1];
  this->ScreenDeviceContext = this->DeviceContext;
  this->ScreenDoubleBuffer = this->DoubleBuffer;
  this->ScreenContextId = this->ContextId;

  this->CreateOffScreenDC(hbmp, dc);
  DeleteDC(dc);
}

Ken Martin's avatar
Ken Martin committed
1549
HDC vtkWin32OpenGLRenderWindow::GetMemoryDC()
Ken Martin's avatar
Ken Martin committed
1550
1551
1552
1553
{
  return this->MemoryHdc;
}

Ken Martin's avatar
Ken Martin committed
1554
void vtkWin32OpenGLRenderWindow::CleanUpOffScreenRendering(void)
Ken Martin's avatar
Ken Martin committed
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
{
  if(this->OffScreenUseFrameBuffer)
    {
    this->DestroyHardwareOffScreenWindow();
    }
  else
    {
    if (!this->MemoryHdc)
      {
      return;
      }

    GdiFlush();

    // we need to release resources
    this->CleanUpRenderers();
    DeleteDC(this->MemoryHdc);
    this->MemoryHdc = (HDC)0;
    DeleteObject(this->MemoryBuffer);
    if (wglDeleteContext(this->ContextId) != TRUE)
      {
      vtkErrorMacro("wglDeleteContext failed in CleanUpOffScreenRendering(), error: " << GetLastError());
      }
    this->ContextId=0;
    }
}

Ken Martin's avatar
Ken Martin committed
1582
void vtkWin32OpenGLRenderWindow::ResumeScreenRendering(void)
Ken Martin's avatar
Ken Martin committed
1583
1584
1585
1586
{
  // release OpenGL graphics resources before switch back to on-screen.
  if(this->ContextId!=0)
    {
1587
1588
    this->MakeCurrent();
    this->ReleaseGraphicsResources(this);
Ken Martin's avatar
Ken Martin committed
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
    }

  this->Mapped = this->ScreenMapped;
  this->Size[0] = this->ScreenWindowSize[0];
  this->Size[1] = this->ScreenWindowSize[1];
  this->DeviceContext = this->ScreenDeviceContext;
  this->DoubleBuffer = this->ScreenDoubleBuffer;
  this->ContextId = this->ScreenContextId;
  this->MakeCurrent();
}

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
1601
void vtkWin32OpenGLRenderWindow::HideCursor()
Ken Martin's avatar
Ken Martin committed
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
{
  if (this->CursorHidden)
    {
    return;
    }
  this->CursorHidden = 1;

  ::ShowCursor(!this->CursorHidden);
}

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
1613
void vtkWin32OpenGLRenderWindow::ShowCursor()
Ken Martin's avatar
Ken Martin committed
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
{
  if (!this->CursorHidden)
    {
    return;
    }
  this->CursorHidden = 0;

  ::ShowCursor(!this->CursorHidden);
}

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
1625
void vtkWin32OpenGLRenderWindow::SetCursorPosition(int x, int y)
Ken Martin's avatar
Ken Martin committed
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
{
  int *size = this->GetSize();

  POINT point;
  point.x = x;
  point.y = size[1] - y - 1;

  if (ClientToScreen(this->WindowId, &point))
    {
    SetCursorPos(point.x, point.y);
    }
}

//----------------------------------------------------------------------------
Ken Martin's avatar
Ken Martin committed
1640
void vtkWin32OpenGLRenderWindow::SetCurrentCursor(int shape)
Ken Martin's avatar
Ken Martin committed
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
{
  if ( this->InvokeEvent(vtkCommand::CursorChangedEvent,&shape) )
    {
    return;
    }
  this->Superclass::SetCurrentCursor(shape);
  LPCTSTR cursorName = 0;
  switch (shape)
    {
    case VTK_CURSOR_DEFAULT:
    case VTK_CURSOR_ARROW:
      cursorName = IDC_ARROW;
      break;
    case VTK_CURSOR_SIZENE:
    case VTK_CURSOR_SIZESW:
      cursorName = IDC_SIZENESW;
      break;
    case VTK_CURSOR_SIZENW:
    case VTK_CURSOR_SIZESE:
      cursorName = IDC_SIZENWSE;
      break;
    case VTK_CURSOR_SIZENS:
      cursorName = IDC_SIZENS;
      break;
    case VTK_CURSOR_SIZEWE:
      cursorName = IDC_SIZEWE;
      break;
    case VTK_CURSOR_SIZEALL:
      cursorName = IDC_SIZEALL;
      break;
    case VTK_CURSOR_HAND:
#if(WINVER >= 0x0500)
      cursorName = IDC_HAND;
#else
      cursorName = IDC_ARROW;
#endif
      break;
    case VTK_CURSOR_CROSSHAIR:
      cursorName = IDC_CROSS;
      break;
    }

  if (cursorName)
    {
    HANDLE cursor =
      LoadImage(0,cursorName,IMAGE_CURSOR,0,0,LR_SHARED | LR_DEFAULTSIZE);
    SetCursor((HCURSOR)cursor);
    }
}
David C. Lonie's avatar
David C. Lonie committed
1690
1691
1692
1693
1694
1695
1696

//----------------------------------------------------------------------------
bool vtkWin32OpenGLRenderWindow::DetectDPI()
{
  this->SetDPI(GetDeviceCaps(this->DeviceContext, LOGPIXELSY));
  return true;
}