34 #ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
50 void G4OpenGLWin32Viewer::SetView (
57 ::wglMakeCurrent(fHDC,fHGLRC);
58 G4OpenGLViewer::SetView ();
62 void G4OpenGLWin32Viewer::ShowView (
71 while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
72 ::TranslateMessage(&event);
73 ::DispatchMessage (&event);
78 void G4OpenGLWin32Viewer::GetWin32Connection (
86 void G4OpenGLWin32Viewer::CreateGLWin32Context (
94 void G4OpenGLWin32Viewer::CreateMainWindow (
102 static const char className[] =
"G4OpenGLWin32";
103 static bool done =
false;
106 wc.style = CS_HREDRAW | CS_VREDRAW;
107 wc.lpfnWndProc = (WNDPROC)WindowProc;
110 wc.hInstance = ::GetModuleHandle(NULL);
111 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
112 wc.hCursor = LoadCursor(NULL,IDC_CROSS);
113 wc.hbrBackground = NULL;
114 wc.lpszMenuName = className;
115 wc.lpszClassName = className;
116 ::RegisterClass(&wc);
120 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
122 int x_res=GetSystemMetrics(SM_CXSCREEN);
123 int y_res=GetSystemMetrics(SM_CYSCREEN);
126 fWindow = ::CreateWindow(className,
fName.c_str(),
130 fVP.GetWindowAbsoluteLocationHintX(x_res),
131 fVP.GetWindowAbsoluteLocationHintY(y_res),
132 getWinWidth(), getWinHeight(),
134 ::GetModuleHandle(NULL),
138 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(
this));
141 fHDC = ::GetDC(fWindow);
142 if( fHDC && (SetWindowPixelFormat(fHDC)==
TRUE) ) {
143 fHGLRC = ::wglCreateContext(fHDC);
147 ::wglMakeCurrent(fHDC,fHGLRC);
150 ::SetForegroundWindow(fWindow);
151 ::ShowWindow(fWindow,SW_SHOWDEFAULT);
152 ::UpdateWindow(fWindow);
153 ::DrawMenuBar(fWindow);
157 G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
158 G4OpenGLSceneHandler& scene
161 ,G4OpenGLViewer (scene)
171 G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
178 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
180 wglDeleteContext(fHGLRC);
185 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(NULL));
186 if(fHDC) ::ReleaseDC(fWindow,fHDC);
187 ::DestroyWindow(fWindow);
193 LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc (
232 return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
236 bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
244 PIXELFORMATDESCRIPTOR pfd;
245 pfd.nSize =
sizeof(PIXELFORMATDESCRIPTOR);
252 pfd.iPixelType = PFD_TYPE_RGBA;
263 pfd.cAccumRedBits = 16;
264 pfd.cAccumGreenBits = 16;
265 pfd.cAccumBlueBits = 16;
266 pfd.cAccumAlphaBits = 0;
268 pfd.cStencilBits = 8;
270 pfd.iLayerType = PFD_MAIN_PLANE;
273 pfd.dwVisibleMask = 0;
274 pfd.dwDamageMask = 0;
276 int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
279 if (::DescribePixelFormat(aHdc,
281 sizeof(PIXELFORMATDESCRIPTOR),
286 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==
FALSE)
return false;