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

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

suppres des debug et modif des WinSize

  • Property svn:mime-type set to text/cpp
File size: 8.7 KB
Line 
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//
27// $Id: G4OpenGLWin32Viewer.cc,v 1.17 2006/06/29 21:19:36 gunter Exp $
28// GEANT4 tag $Name: HEAD $
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
119 fWindow = ::CreateWindow(className,fName.c_str(),
120 WS_OVERLAPPEDWINDOW,
121 //WS_CHILD | WS_VISIBLE,
122 0,0,
123 fWinSize_x,fWinSize_y,
124 NULL, NULL,
125 ::GetModuleHandle(NULL),
126 NULL);
127 if(!fWindow) return;
128
129 ::SetWindowLong(fWindow,GWL_USERDATA,LONG(this));
130
131 // initialize OpenGL rendering :
132 fHDC = ::GetDC(fWindow);
133 if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
134 fHGLRC = ::wglCreateContext(fHDC);
135 }
136
137 if(fHDC && fHGLRC) {
138 ::wglMakeCurrent(fHDC,fHGLRC);
139 }
140
141 ::SetForegroundWindow(fWindow);
142 ::ShowWindow(fWindow,SW_SHOWDEFAULT);
143 ::UpdateWindow(fWindow);
144 ::DrawMenuBar(fWindow);
145}
146
147//////////////////////////////////////////////////////////////////////////////
148G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
149 G4OpenGLSceneHandler& scene
150)
151:G4VViewer (scene, -1)
152,G4OpenGLViewer (scene)
153,fWindow(0)
154,fHDC(0)
155,fHGLRC(0)
156//////////////////////////////////////////////////////////////////////////////
157//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
158{
159}
160
161//////////////////////////////////////////////////////////////////////////////
162G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
163)
164//////////////////////////////////////////////////////////////////////////////
165//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
166{
167 // This is the end (Jim Morisson).
168 if (fViewId >= 0) {
169 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
170 if(fHGLRC) {
171 wglDeleteContext(fHGLRC);
172 fHGLRC = NULL;
173 }
174
175 if(fWindow) {
176 ::SetWindowLong(fWindow,GWL_USERDATA,LONG(NULL));
177 if(fHDC) ::ReleaseDC(fWindow,fHDC);
178 ::DestroyWindow(fWindow);
179 }
180 }
181}
182
183//////////////////////////////////////////////////////////////////////////////
184LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc (
185 HWND aWindow
186,UINT aMessage
187,WPARAM aWParam
188,LPARAM aLParam
189)
190//////////////////////////////////////////////////////////////////////////////
191//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
192{
193/*
194 switch (aMessage) {
195 case WM_PAINT:{
196 printf("debug : PAINT\n");
197 HDC hDC;
198 PAINTSTRUCT ps;
199 hDC = BeginPaint(aWindow,&ps);
200 if(This) {
201 // FIXME : To have an automatic refresh someone have to redraw here.
202 }
203 EndPaint(aWindow, &ps);
204
205 //FIXME : have to handle WM_RESIZE
206 //pView->fWinSize_x = (G4int) width;
207 //pView->fWinSize_y = (G4int) height;
208 G4OpenGLWin32Viewer* This =
209 (G4OpenGLWin32Viewer*)::GetWindowLong(aWindow,GWL_USERDATA);
210 if(This) {
211 This->SetView();
212 glViewport(0,0,This->fWinSize_x,This->fWinSize_y);
213 This->ClearView();
214 This->DrawView();
215 // WARNING : the below empty the Windows message queue...
216 This->FinishView();
217 }
218 } return 0;
219 default:
220 return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
221 }
222*/
223 return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
224}
225
226//////////////////////////////////////////////////////////////////////////////
227bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
228 HDC aHdc
229)
230//////////////////////////////////////////////////////////////////////////////
231//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
232{
233 // The ungessable...
234
235 PIXELFORMATDESCRIPTOR pfd;
236 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
237 pfd.nVersion = 1;
238 pfd.dwFlags =
239 PFD_DRAW_TO_WINDOW |
240 PFD_SUPPORT_OPENGL |
241 PFD_DOUBLEBUFFER |
242 PFD_STEREO_DONTCARE;
243 pfd.iPixelType = PFD_TYPE_RGBA;
244 pfd.cColorBits = 32;
245 pfd.cRedBits = 8;
246 pfd.cRedShift = 16;
247 pfd.cGreenBits = 8;
248 pfd.cGreenShift = 8;
249 pfd.cBlueBits = 8;
250 pfd.cBlueShift = 0;
251 pfd.cAlphaBits = 0;
252 pfd.cAlphaShift = 0;
253 pfd.cAccumBits = 64;
254 pfd.cAccumRedBits = 16;
255 pfd.cAccumGreenBits = 16;
256 pfd.cAccumBlueBits = 16;
257 pfd.cAccumAlphaBits = 0;
258 pfd.cDepthBits = 32;
259 pfd.cStencilBits = 8;
260 pfd.cAuxBuffers = 0;
261 pfd.iLayerType = PFD_MAIN_PLANE;
262 pfd.bReserved = 0;
263 pfd.dwLayerMask = 0;
264 pfd.dwVisibleMask = 0;
265 pfd.dwDamageMask = 0;
266
267 int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
268 if (pixelIndex==0) {
269 pixelIndex = 1;
270 if (::DescribePixelFormat(aHdc,
271 pixelIndex,
272 sizeof(PIXELFORMATDESCRIPTOR),
273 &pfd)==0) {
274 return false;
275 }
276 }
277 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
278 return true;
279}
280
281
282#endif
Note: See TracBrowser for help on using the repository browser.