00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
00036
00037 #include "G4OpenGLWin32Viewer.hh"
00038 #include "G4VViewer.hh"
00039 #include "G4VSceneHandler.hh"
00040 #include "G4OpenGLSceneHandler.hh"
00041
00042 #include "G4ios.hh"
00043 #include "G4VisExtent.hh"
00044 #include "G4LogicalVolume.hh"
00045 #include "G4VSolid.hh"
00046 #include "G4Point3D.hh"
00047 #include "G4Normal3D.hh"
00048
00049
00051 void G4OpenGLWin32Viewer::SetView (
00052 )
00053
00054
00055 {
00056 if(!fHDC) return;
00057 if(!fHGLRC) return;
00058 ::wglMakeCurrent(fHDC,fHGLRC);
00059 G4OpenGLViewer::SetView ();
00060 }
00061
00063 void G4OpenGLWin32Viewer::ShowView (
00064 )
00065
00066
00067 {
00068 if(!fHDC) return;
00069 glFlush ();
00070
00071 MSG event;
00072 while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
00073 ::TranslateMessage(&event);
00074 ::DispatchMessage (&event);
00075 }
00076 }
00077
00079 void G4OpenGLWin32Viewer::GetWin32Connection (
00080 )
00081
00082
00083 {
00084 }
00085
00087 void G4OpenGLWin32Viewer::CreateGLWin32Context (
00088 )
00089
00090
00091 {
00092 }
00093
00095 void G4OpenGLWin32Viewer::CreateMainWindow (
00096 )
00097
00098
00099 {
00100 if(fWindow) return;
00101
00102
00103 static const char className[] = "G4OpenGLWin32";
00104 static bool done = false;
00105 if(done==false) {
00106 WNDCLASS wc;
00107 wc.style = CS_HREDRAW | CS_VREDRAW;
00108 wc.lpfnWndProc = (WNDPROC)WindowProc;
00109 wc.cbClsExtra = 0;
00110 wc.cbWndExtra = 0;
00111 wc.hInstance = ::GetModuleHandle(NULL);
00112 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
00113 wc.hCursor = LoadCursor(NULL,IDC_CROSS);
00114 wc.hbrBackground = NULL;
00115 wc.lpszMenuName = className;
00116 wc.lpszClassName = className;
00117 ::RegisterClass(&wc);
00118 done = true;
00119 }
00120
00121 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
00122
00123 int x_res=GetSystemMetrics(SM_CXSCREEN);
00124 int y_res=GetSystemMetrics(SM_CYSCREEN);
00125
00126
00127 fWindow = ::CreateWindow(className,fName.c_str(),
00128 WS_OVERLAPPEDWINDOW,
00129
00130
00131 fVP.GetWindowAbsoluteLocationHintX(x_res),
00132 fVP.GetWindowAbsoluteLocationHintY(y_res),
00133 getWinWidth(), getWinHeight(),
00134 NULL, NULL,
00135 ::GetModuleHandle(NULL),
00136 NULL);
00137 if(!fWindow) return;
00138
00139 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(this));
00140
00141
00142 fHDC = ::GetDC(fWindow);
00143 if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
00144 fHGLRC = ::wglCreateContext(fHDC);
00145 }
00146
00147 if(fHDC && fHGLRC) {
00148 ::wglMakeCurrent(fHDC,fHGLRC);
00149 }
00150
00151 ::SetForegroundWindow(fWindow);
00152 ::ShowWindow(fWindow,SW_SHOWDEFAULT);
00153 ::UpdateWindow(fWindow);
00154 ::DrawMenuBar(fWindow);
00155 }
00156
00158 G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
00159 G4OpenGLSceneHandler& scene
00160 )
00161 :G4VViewer (scene, -1)
00162 ,G4OpenGLViewer (scene)
00163 ,fWindow(0)
00164 ,fHDC(0)
00165 ,fHGLRC(0)
00168 {
00169 }
00170
00172 G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
00173 )
00174
00175
00176 {
00177
00178 if (fViewId >= 0) {
00179 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
00180 if(fHGLRC) {
00181 wglDeleteContext(fHGLRC);
00182 fHGLRC = NULL;
00183 }
00184
00185 if(fWindow) {
00186 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(NULL));
00187 if(fHDC) ::ReleaseDC(fWindow,fHDC);
00188 ::DestroyWindow(fWindow);
00189 }
00190 }
00191 }
00192
00194 LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc (
00195 HWND aWindow
00196 ,UINT aMessage
00197 ,WPARAM aWParam
00198 ,LPARAM aLParam
00199 )
00202 {
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
00234 }
00235
00237 bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
00238 HDC aHdc
00239 )
00242 {
00243
00244
00245 PIXELFORMATDESCRIPTOR pfd;
00246 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
00247 pfd.nVersion = 1;
00248 pfd.dwFlags =
00249 PFD_DRAW_TO_WINDOW |
00250 PFD_SUPPORT_OPENGL |
00251 PFD_DOUBLEBUFFER |
00252 PFD_STEREO_DONTCARE;
00253 pfd.iPixelType = PFD_TYPE_RGBA;
00254 pfd.cColorBits = 32;
00255 pfd.cRedBits = 8;
00256 pfd.cRedShift = 16;
00257 pfd.cGreenBits = 8;
00258 pfd.cGreenShift = 8;
00259 pfd.cBlueBits = 8;
00260 pfd.cBlueShift = 0;
00261 pfd.cAlphaBits = 0;
00262 pfd.cAlphaShift = 0;
00263 pfd.cAccumBits = 64;
00264 pfd.cAccumRedBits = 16;
00265 pfd.cAccumGreenBits = 16;
00266 pfd.cAccumBlueBits = 16;
00267 pfd.cAccumAlphaBits = 0;
00268 pfd.cDepthBits = 32;
00269 pfd.cStencilBits = 8;
00270 pfd.cAuxBuffers = 0;
00271 pfd.iLayerType = PFD_MAIN_PLANE;
00272 pfd.bReserved = 0;
00273 pfd.dwLayerMask = 0;
00274 pfd.dwVisibleMask = 0;
00275 pfd.dwDamageMask = 0;
00276
00277 int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
00278 if (pixelIndex==0) {
00279 pixelIndex = 1;
00280 if (::DescribePixelFormat(aHdc,
00281 pixelIndex,
00282 sizeof(PIXELFORMATDESCRIPTOR),
00283 &pfd)==0) {
00284 return false;
00285 }
00286 }
00287 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
00288 return true;
00289 }
00290
00291
00292 #endif