source: trunk/source/visualization/OpenGL/src/G4OpenGLWin32Viewer.cc@ 1023

Last change on this file since 1023 was 906, checked in by garnier, 17 years ago

for aspect radio. Ok for Qt, Xm, but not X. Debug mode

  • Property svn:mime-type set to text/cpp
File size: 9.0 KB
RevLine 
[529]1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
[906]27// $Id: G4OpenGLWin32Viewer.cc,v 1.18 2009/01/13 09:47:05 lgarnier Exp $
28// GEANT4 tag $Name: $
[529]29//
30//
31// G4OpenGLWin32Viewer : Class to provide WindowsNT specific
32// functionality for OpenGL in GEANT4
33//
34// 27/06/2003 : G.Barrand : implementation (at last !).
35
36#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
37
38#include "G4OpenGLWin32Viewer.hh"
39
40#include "G4ios.hh"
41#include "G4VisExtent.hh"
42#include "G4LogicalVolume.hh"
43#include "G4VSolid.hh"
44#include "G4Point3D.hh"
45#include "G4Normal3D.hh"
46
47
48//////////////////////////////////////////////////////////////////////////////
49void G4OpenGLWin32Viewer::SetView (
50)
51//////////////////////////////////////////////////////////////////////////////
52//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
53{
54 if(!fHDC) return;
55 if(!fHGLRC) return;
56 ::wglMakeCurrent(fHDC,fHGLRC);
57 G4OpenGLViewer::SetView ();
58}
59
60//////////////////////////////////////////////////////////////////////////////
61void G4OpenGLWin32Viewer::ShowView (
62)
63//////////////////////////////////////////////////////////////////////////////
64//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
65{
66 if(!fHDC) return;
67 glFlush ();
68 // Empty the Windows message queue :
69 MSG event;
70 while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
71 ::TranslateMessage(&event);
72 ::DispatchMessage (&event);
73 }
74}
75
76//////////////////////////////////////////////////////////////////////////////
77void G4OpenGLWin32Viewer::GetWin32Connection (
78)
79//////////////////////////////////////////////////////////////////////////////
80//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
81{
82}
83
84//////////////////////////////////////////////////////////////////////////////
85void G4OpenGLWin32Viewer::CreateGLWin32Context (
86)
87//////////////////////////////////////////////////////////////////////////////
88//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
89{
90}
91
92//////////////////////////////////////////////////////////////////////////////
93void G4OpenGLWin32Viewer::CreateMainWindow (
94)
95//////////////////////////////////////////////////////////////////////////////
96//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
97{
98 if(fWindow) return; //Done.
99
100 // Bill Gates stuff...
101 static const char className[] = "G4OpenGLWin32";
102 static bool done = false;
103 if(done==false) {
104 WNDCLASS wc;
105 wc.style = CS_HREDRAW | CS_VREDRAW;
106 wc.lpfnWndProc = (WNDPROC)WindowProc;
107 wc.cbClsExtra = 0;
108 wc.cbWndExtra = 0;
109 wc.hInstance = ::GetModuleHandle(NULL);
110 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
111 wc.hCursor = LoadCursor(NULL,IDC_CROSS);
112 wc.hbrBackground = NULL;
113 wc.lpszMenuName = className;
114 wc.lpszClassName = className;
115 ::RegisterClass(&wc);
116 done = true;
117 }
118
[898]119 fWinSize_x = fVP.GetWindowSizeHintX();
120 fWinSize_y = fVP.GetWindowSizeHintY();
121 int x_res=GetSystemMetrics(SM_CXSCREEN);
122 int y_res=GetSystemMetrics(SM_CYSCREEN);
123
124 //FIXME : NOT tested !
[529]125 fWindow = ::CreateWindow(className,fName.c_str(),
126 WS_OVERLAPPEDWINDOW,
127 //WS_CHILD | WS_VISIBLE,
[898]128 // 0,0,
129 fVP.GetWindowAbsoluteLocationHintX(x_res),
130 fVP.GetWindowAbsoluteLocationHintY(y_res),
[897]131 fWinSize_x,fWinSize_y,
[529]132 NULL, NULL,
133 ::GetModuleHandle(NULL),
134 NULL);
135 if(!fWindow) return;
136
137 ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
138
139 // initialize OpenGL rendering :
140 fHDC = ::GetDC(fWindow);
141 if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
142 fHGLRC = ::wglCreateContext(fHDC);
143 }
144
145 if(fHDC && fHGLRC) {
146 ::wglMakeCurrent(fHDC,fHGLRC);
147 }
148
149 ::SetForegroundWindow(fWindow);
150 ::ShowWindow(fWindow,SW_SHOWDEFAULT);
151 ::UpdateWindow(fWindow);
152 ::DrawMenuBar(fWindow);
153}
154
155//////////////////////////////////////////////////////////////////////////////
156G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
157 G4OpenGLSceneHandler& scene
158)
159:G4VViewer (scene, -1)
160,G4OpenGLViewer (scene)
161,fWindow(0)
162,fHDC(0)
163,fHGLRC(0)
164//////////////////////////////////////////////////////////////////////////////
165//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
166{
167}
168
169//////////////////////////////////////////////////////////////////////////////
170G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
171)
172//////////////////////////////////////////////////////////////////////////////
173//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
174{
175 // This is the end (Jim Morisson).
176 if (fViewId >= 0) {
177 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
178 if(fHGLRC) {
179 wglDeleteContext(fHGLRC);
180 fHGLRC = NULL;
181 }
182
183 if(fWindow) {
184 ::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL));
185 if(fHDC) ::ReleaseDC(fWindow,fHDC);
186 ::DestroyWindow(fWindow);
187 }
188 }
189}
190
191//////////////////////////////////////////////////////////////////////////////
192LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc (
193 HWND aWindow
194,UINT aMessage
195,WPARAM aWParam
196,LPARAM aLParam
197)
198//////////////////////////////////////////////////////////////////////////////
199//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
200{
201/*
202 switch (aMessage) {
203 case WM_PAINT:{
204 printf("debug : PAINT\n");
205 HDC hDC;
206 PAINTSTRUCT ps;
207 hDC = BeginPaint(aWindow,&ps);
208 if(This) {
209 // FIXME : To have an automatic refresh someone have to redraw here.
210 }
211 EndPaint(aWindow, &ps);
212
213 //FIXME : have to handle WM_RESIZE
[897]214 //pView->fWinSize_x = (G4int) width;
215 //pView->fWinSize_y = (G4int) height;
[529]216 G4OpenGLWin32Viewer* This =
217 (G4OpenGLWin32Viewer*)::GetWindowLong(aWindow,GWL_USERDATA);
218 if(This) {
219 This->SetView();
[897]220 glViewport(0,0,This->fWinSize_x,This->fWinSize_y);
[529]221 This->ClearView();
222 This->DrawView();
223 // WARNING : the below empty the Windows message queue...
224 This->FinishView();
225 }
226 } return 0;
227 default:
228 return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
229 }
230*/
231 return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
232}
233
234//////////////////////////////////////////////////////////////////////////////
235bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
236 HDC aHdc
237)
238//////////////////////////////////////////////////////////////////////////////
239//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
240{
241 // The ungessable...
242
243 PIXELFORMATDESCRIPTOR pfd;
244 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
245 pfd.nVersion = 1;
246 pfd.dwFlags =
247 PFD_DRAW_TO_WINDOW |
248 PFD_SUPPORT_OPENGL |
249 PFD_DOUBLEBUFFER |
250 PFD_STEREO_DONTCARE;
251 pfd.iPixelType = PFD_TYPE_RGBA;
252 pfd.cColorBits = 32;
253 pfd.cRedBits = 8;
254 pfd.cRedShift = 16;
255 pfd.cGreenBits = 8;
256 pfd.cGreenShift = 8;
257 pfd.cBlueBits = 8;
258 pfd.cBlueShift = 0;
259 pfd.cAlphaBits = 0;
260 pfd.cAlphaShift = 0;
261 pfd.cAccumBits = 64;
262 pfd.cAccumRedBits = 16;
263 pfd.cAccumGreenBits = 16;
264 pfd.cAccumBlueBits = 16;
265 pfd.cAccumAlphaBits = 0;
266 pfd.cDepthBits = 32;
267 pfd.cStencilBits = 8;
268 pfd.cAuxBuffers = 0;
269 pfd.iLayerType = PFD_MAIN_PLANE;
270 pfd.bReserved = 0;
271 pfd.dwLayerMask = 0;
272 pfd.dwVisibleMask = 0;
273 pfd.dwDamageMask = 0;
274
275 int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
276 if (pixelIndex==0) {
277 pixelIndex = 1;
278 if (::DescribePixelFormat(aHdc,
279 pixelIndex,
280 sizeof(PIXELFORMATDESCRIPTOR),
281 &pfd)==0) {
282 return false;
283 }
284 }
285 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
286 return true;
287}
288
289
290#endif
Note: See TracBrowser for help on using the repository browser.