54 ::wglMakeCurrent(
fHDC,fHGLRC);
68 while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
69 ::TranslateMessage(&event);
70 ::DispatchMessage (&event);
108 static const char className[] =
"G4OpenGLWin32";
109 static G4bool done =
false;
112 wc.style = CS_HREDRAW | CS_VREDRAW;
113 wc.lpfnWndProc = (WNDPROC)WindowProc;
116 wc.hInstance = ::GetModuleHandle(NULL);
117 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
118 wc.hCursor = LoadCursor(NULL,IDC_CROSS);
119 wc.hbrBackground = NULL;
120 wc.lpszMenuName = (PTSTR)className;
121 wc.lpszClassName = (PTSTR)className;
122 ::RegisterClass(&wc);
128 G4int x_res=GetSystemMetrics(SM_CXSCREEN);
129 G4int y_res=GetSystemMetrics(SM_CYSCREEN);
132 fWindow = ::CreateWindowEx(0, (PTSTR)className, (PTSTR)
fName.c_str(),
136 fVP.GetWindowAbsoluteLocationHintX(x_res),
137 fVP.GetWindowAbsoluteLocationHintY(y_res),
140 ::GetModuleHandle(NULL),
144 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(
this));
147 fHDC = ::GetDC(fWindow);
149 fHGLRC = ::wglCreateContext(
fHDC);
153 ::wglMakeCurrent(
fHDC,fHGLRC);
159 fInCreateWindow =
true;
161 ::SetForegroundWindow(fWindow);
162 ::ShowWindow(fWindow,SW_SHOWDEFAULT);
163 ::UpdateWindow(fWindow);
164 ::DrawMenuBar(fWindow);
166 fInCreateWindow =
false;
182,fInCreateWindow(false)
196 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
198 wglDeleteContext(fHGLRC);
203 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(NULL));
205 ::DestroyWindow(fWindow);
211LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc(
225 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
227 This->fWinSize_x = (
G4int) LOWORD(aLParam);
228 This->fWinSize_y = (
G4int) HIWORD(aLParam);
229 if (!This->fInCreateWindow) {
231 glViewport(0, 0, This->fWinSize_x, This->fWinSize_y);
240 BeginPaint(aWindow, &ps);
242 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
246 if(!This->fInCreateWindow) {
252 EndPaint(aWindow, &ps);
256 case WM_LBUTTONDOWN: {
258 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
259 This->TrackMouse(LOWORD(aLParam), HIWORD(aLParam));
263 case WM_RBUTTONDOWN: {
265 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
266 This->TrackMouse(LOWORD(aLParam), HIWORD(aLParam));
272 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
273 This->ReleaseMouse();
279 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
280 This->ReleaseMouse();
284 case WM_MOUSEHOVER: {
286 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
287 This->fMouseHovered =
true;
291 case WM_MOUSELEAVE: {
293 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
294 This->fMouseHovered =
false;
300 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
302 if (!This->fMouseHovered) {
305 tme.cbSize =
sizeof(tme);
306 tme.dwFlags = TME_HOVER | TME_LEAVE;
307 tme.hwndTrack = aWindow;
308 tme.dwHoverTime = HOVER_DEFAULT;
309 ::TrackMouseEvent(&tme);
310 This->fMouseHovered =
true;
313 if (This->fMousePressed) {
316 G4int dx = x - This->fMousePressedX;
317 G4int dy = y - This->fMousePressedY;
318 This->fMousePressedX = x;
319 This->fMousePressedY = y;
321 if (aWParam == MK_LBUTTON) {
322 This->SetRotation(dx, dy);
325 if (aWParam == MK_RBUTTON) {
326 This->SetShift(dx, dy);
337 case WM_MOUSEWHEEL: {
339 ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
341 G4int delta = (short) HIWORD(aWParam);
343 This->SetZoom(delta);
351 return DefWindowProc(aWindow, aMessage, aWParam, aLParam);
357G4bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
365 PIXELFORMATDESCRIPTOR pfd;
366 pfd.nSize =
sizeof(PIXELFORMATDESCRIPTOR);
373 pfd.iPixelType = PFD_TYPE_RGBA;
384 pfd.cAccumRedBits = 16;
385 pfd.cAccumGreenBits = 16;
386 pfd.cAccumBlueBits = 16;
387 pfd.cAccumAlphaBits = 0;
389 pfd.cStencilBits = 8;
391 pfd.iLayerType = PFD_MAIN_PLANE;
394 pfd.dwVisibleMask = 0;
395 pfd.dwDamageMask = 0;
397 G4int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
400 if (::DescribePixelFormat(aHdc,
402 sizeof(PIXELFORMATDESCRIPTOR),
407 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==
FALSE)
return false;
412void G4OpenGLWin32Viewer::TrackMouse(
425void G4OpenGLWin32Viewer::ReleaseMouse(
436void G4OpenGLWin32Viewer::SetShift(
446 const G4double dxScene = dx*sceneRadius/scale;
447 const G4double dyScene = dy*sceneRadius/scale;
448 fVP.IncrementPan(-dxScene,dyScene);
452void G4OpenGLWin32Viewer::SetRotation(
461 .cross(
fVP.GetUpVector());
464 G4Vector3D newViewpointDirection =
fVP.GetViewpointDirection();
465 newViewpointDirection += dx*x_prime/scale;
466 newViewpointDirection += dy*y_prime/scale;
467 fVP.SetViewpointDirection(newViewpointDirection.
unit());
471 newUpVector += dx*x_prime/scale;
472 newUpVector += dy*y_prime/scale;
473 fVP.SetUpVector(newUpVector.
unit());
478void G4OpenGLWin32Viewer::SetZoom(
G4int delta)
483 GetCursorPos(&mousePos);
484 ScreenToClient(fWindow, &mousePos);
490G4bool G4OpenGLWin32Viewer::GetWindowSize(
unsigned int& a_w,
unsigned int& a_h)
497G4bool G4OpenGLWin32Viewer::GetRenderAreaSize(
unsigned int& a_w,
unsigned int& a_h)
HepGeom::Vector3D< G4double > G4Vector3D
friend class G4OpenGLSceneHandler
unsigned int getWinHeight() const
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
G4OpenGLViewer(G4OpenGLSceneHandler &scene)
virtual void CreateMainWindow()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
G4OpenGLWin32Viewer(G4OpenGLSceneHandler &scene)
void ShowView()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void SetView()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void SwitchToMasterThread()
virtual ~G4OpenGLWin32Viewer()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void CreateGLWin32Context()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void GetWin32Connection()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
const G4VisExtent & GetExtent() const
G4Scene * GetScene() const
G4VSceneHandler & fSceneHandler
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
G4VSceneHandler * GetSceneHandler() const
void ZoomFromMouseWheel(G4double delta, G4bool shift=false, G4double xPos=0, G4double yPos=0)
G4double GetExtentRadius() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const
G4bool IsMultithreadedApplication()