54 ::wglMakeCurrent(
fHDC,fHGLRC);
68 while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
69 ::TranslateMessage(&event);
70 ::DispatchMessage (&event);
99 static const char className[] =
"G4OpenGLWin32";
100 static G4bool done =
false;
103 wc.style = CS_HREDRAW | CS_VREDRAW;
104 wc.lpfnWndProc = (WNDPROC)WindowProc;
107 wc.hInstance = ::GetModuleHandle(NULL);
108 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
109 wc.hCursor = LoadCursor(NULL,IDC_CROSS);
110 wc.hbrBackground = NULL;
111 wc.lpszMenuName = className;
112 wc.lpszClassName = className;
113 ::RegisterClass(&wc);
119 G4int x_res=GetSystemMetrics(SM_CXSCREEN);
120 G4int y_res=GetSystemMetrics(SM_CYSCREEN);
123 fWindow = ::CreateWindowEx(0, className,
fName.c_str(),
131 ::GetModuleHandle(NULL),
135 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(
this));
138 fHDC = ::GetDC(fWindow);
140 fHGLRC = ::wglCreateContext(
fHDC);
144 ::wglMakeCurrent(
fHDC,fHGLRC);
150 fInCreateWindow =
true;
152 ::SetForegroundWindow(fWindow);
153 ::ShowWindow(fWindow,SW_SHOWDEFAULT);
154 ::UpdateWindow(fWindow);
155 ::DrawMenuBar(fWindow);
157 fInCreateWindow =
false;
173,fInCreateWindow(false)
187 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
189 wglDeleteContext(fHGLRC);
194 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(NULL));
196 ::DestroyWindow(fWindow);
202LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc(
216 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
218 This->fWinSize_x = (
G4int) LOWORD(aLParam);
219 This->fWinSize_y = (
G4int) HIWORD(aLParam);
220 if (!This->fInCreateWindow) {
222 glViewport(0, 0, This->fWinSize_x, This->fWinSize_y);
231 BeginPaint(aWindow, &ps);
233 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
237 if(!This->fInCreateWindow) {
243 EndPaint(aWindow, &ps);
247 case WM_LBUTTONDOWN: {
249 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
250 This->TrackMouse(LOWORD(aLParam), HIWORD(aLParam));
254 case WM_RBUTTONDOWN: {
256 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
257 This->TrackMouse(LOWORD(aLParam), HIWORD(aLParam));
263 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
264 This->ReleaseMouse();
270 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
271 This->ReleaseMouse();
275 case WM_MOUSEHOVER: {
277 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
278 This->fMouseHovered =
true;
282 case WM_MOUSELEAVE: {
284 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
285 This->fMouseHovered =
false;
291 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
293 if (!This->fMouseHovered) {
296 tme.cbSize =
sizeof(tme);
297 tme.dwFlags = TME_HOVER | TME_LEAVE;
298 tme.hwndTrack = aWindow;
299 tme.dwHoverTime = HOVER_DEFAULT;
300 ::TrackMouseEvent(&tme);
301 This->fMouseHovered =
true;
304 if (This->fMousePressed) {
307 G4int dx = x - This->fMousePressedX;
308 G4int dy = y - This->fMousePressedY;
309 This->fMousePressedX = x;
310 This->fMousePressedY = y;
312 if (aWParam == MK_LBUTTON) {
313 This->SetRotation(dx, dy);
316 if (aWParam == MK_RBUTTON) {
317 This->SetShift(dx, dy);
328 case WM_MOUSEWHEEL: {
330 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
332 G4int delta = (short) HIWORD(aWParam);
334 This->SetZoom(delta);
343 return DefWindowProc(aWindow, aMessage, aWParam, aLParam);
349G4bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
357 PIXELFORMATDESCRIPTOR pfd;
358 pfd.nSize =
sizeof(PIXELFORMATDESCRIPTOR);
365 pfd.iPixelType = PFD_TYPE_RGBA;
376 pfd.cAccumRedBits = 16;
377 pfd.cAccumGreenBits = 16;
378 pfd.cAccumBlueBits = 16;
379 pfd.cAccumAlphaBits = 0;
381 pfd.cStencilBits = 8;
383 pfd.iLayerType = PFD_MAIN_PLANE;
386 pfd.dwVisibleMask = 0;
387 pfd.dwDamageMask = 0;
389 G4int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
392 if (::DescribePixelFormat(aHdc,
394 sizeof(PIXELFORMATDESCRIPTOR),
399 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==
FALSE)
return false;
404void G4OpenGLWin32Viewer::TrackMouse(
417void G4OpenGLWin32Viewer::ReleaseMouse(
428void G4OpenGLWin32Viewer::SetShift(
438 const G4double dxScene = dx*sceneRadius/scale;
439 const G4double dyScene = dy*sceneRadius/scale;
444void G4OpenGLWin32Viewer::SetRotation(
457 newViewpointDirection += dx*x_prime/scale;
458 newViewpointDirection += dy*y_prime/scale;
463 newUpVector += dx*x_prime/scale;
464 newUpVector += dy*y_prime/scale;
470void G4OpenGLWin32Viewer::SetZoom(
unsigned int getWinHeight() const
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
virtual void CreateMainWindow()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
G4OpenGLWin32Viewer(G4OpenGLSceneHandler &scene)
void ShowView()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void SetView()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual ~G4OpenGLWin32Viewer()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void CreateGLWin32Context()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void GetWin32Connection()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
const G4VisExtent & GetExtent() const
G4Scene * GetScene() const
G4VSceneHandler * GetSceneHandler() const
void SetViewpointDirection(const G4Vector3D &viewpointDirection)
G4int GetWindowAbsoluteLocationHintY(G4int) const
unsigned int GetWindowSizeHintX() const
const G4Vector3D & GetViewpointDirection() const
G4double GetFieldHalfAngle() const
void SetDolly(G4double dolly)
G4int GetWindowAbsoluteLocationHintX(G4int) const
void IncrementPan(G4double right, G4double up)
const G4Vector3D & GetUpVector() const
void SetUpVector(const G4Vector3D &upVector)
RotationStyle GetRotationStyle() const
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
unsigned int GetWindowSizeHintY() const
G4double GetDolly() const
G4double GetExtentRadius() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const