Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenGLXViewer.cc,v 1.56 2010-11-10 17:57:16 allison Exp $ >> 28 // GEANT4 tag $Name: geant4-09-04-patch-01 $ 27 // 29 // 28 // 30 // 29 // Andrew Walkden 7th February 1997 31 // Andrew Walkden 7th February 1997 30 // G4OpenGLXViewer : Class to provide XWindows 32 // G4OpenGLXViewer : Class to provide XWindows specific 31 // functionality for OpenGL in 33 // functionality for OpenGL in GEANT4 32 34 33 #include "G4OpenGLXViewer.hh" << 35 #ifdef G4VIS_BUILD_OPENGLX_DRIVER 34 36 >> 37 #include "G4OpenGLXViewer.hh" >> 38 #include "G4VViewer.hh" 35 #include "G4OpenGLSceneHandler.hh" 39 #include "G4OpenGLSceneHandler.hh" >> 40 #include <GL/glu.h> >> 41 36 #include "G4OpenGLFontBaseStore.hh" 42 #include "G4OpenGLFontBaseStore.hh" 37 43 >> 44 #include <sstream> >> 45 38 #include "G4VisExtent.hh" 46 #include "G4VisExtent.hh" 39 #include "G4LogicalVolume.hh" 47 #include "G4LogicalVolume.hh" 40 #include "G4VSolid.hh" 48 #include "G4VSolid.hh" 41 #include "G4Point3D.hh" 49 #include "G4Point3D.hh" 42 #include "G4Normal3D.hh" 50 #include "G4Normal3D.hh" 43 #include "G4StateManager.hh" 51 #include "G4StateManager.hh" 44 #include "G4VisManager.hh" 52 #include "G4VisManager.hh" 45 #include "G4Text.hh" << 46 #include "G4Threading.hh" << 47 53 48 #include <X11/Xatom.h> 54 #include <X11/Xatom.h> 49 #include <X11/Xutil.h> 55 #include <X11/Xutil.h> 50 #include <X11/Xmu/StdCmap.h> 56 #include <X11/Xmu/StdCmap.h> 51 57 52 #include <assert.h> 58 #include <assert.h> 53 #include <sstream> << 54 #include <chrono> << 55 #include <thread> << 56 59 57 int G4OpenGLXViewer::snglBuf_RGBA[12] = 60 int G4OpenGLXViewer::snglBuf_RGBA[12] = 58 { GLX_RGBA, 61 { GLX_RGBA, 59 GLX_RED_SIZE, 1, 62 GLX_RED_SIZE, 1, 60 GLX_GREEN_SIZE, 1, 63 GLX_GREEN_SIZE, 1, 61 GLX_BLUE_SIZE, 1, 64 GLX_BLUE_SIZE, 1, 62 GLX_DEPTH_SIZE, 1, 65 GLX_DEPTH_SIZE, 1, 63 GLX_STENCIL_SIZE, 1, 66 GLX_STENCIL_SIZE, 1, 64 None }; 67 None }; 65 68 66 int G4OpenGLXViewer::dblBuf_RGBA[13] = 69 int G4OpenGLXViewer::dblBuf_RGBA[13] = 67 { GLX_RGBA, 70 { GLX_RGBA, 68 GLX_RED_SIZE, 1, 71 GLX_RED_SIZE, 1, 69 GLX_GREEN_SIZE, 1, 72 GLX_GREEN_SIZE, 1, 70 GLX_BLUE_SIZE, 1, 73 GLX_BLUE_SIZE, 1, 71 GLX_DOUBLEBUFFER, 74 GLX_DOUBLEBUFFER, 72 GLX_DEPTH_SIZE, 1, 75 GLX_DEPTH_SIZE, 1, 73 GLX_STENCIL_SIZE, 1, 76 GLX_STENCIL_SIZE, 1, 74 None }; 77 None }; 75 78 76 #define NewString(str) \ 79 #define NewString(str) \ 77 ((str) != 0 ? (strncpy((char*)malloc((unsign << 80 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL) 78 81 79 #define USE_DEFAULT_COLORMAP 1 82 #define USE_DEFAULT_COLORMAP 1 80 #define USE_STANDARD_COLORMAP 0 83 #define USE_STANDARD_COLORMAP 0 81 84 82 XVisualInfo* G4OpenGLXViewer::vi_single_buffe 85 XVisualInfo* G4OpenGLXViewer::vi_single_buffer = 0; 83 XVisualInfo* G4OpenGLXViewer::vi_double_buffe 86 XVisualInfo* G4OpenGLXViewer::vi_double_buffer = 0; 84 87 85 extern "C" { 88 extern "C" { 86 static Bool G4OpenGLXViewerWaitForNotify (Di 89 static Bool G4OpenGLXViewerWaitForNotify (Display*, XEvent* e, char* arg) { 87 return (e->type == MapNotify) && (e->xmap. 90 return (e->type == MapNotify) && (e->xmap.window == (Window) arg); 88 } 91 } 89 } 92 } 90 93 91 void G4OpenGLXViewer::SetView () { 94 void G4OpenGLXViewer::SetView () { 92 if (G4Threading::IsMasterThread()) { << 95 Bool success = glXMakeCurrent (dpy, win, cx); 93 glXMakeCurrent (dpy, win, cxMaster); << 96 if (!success) { 94 } else { << 97 fViewId = -1; // This flags an error. 95 glXMakeCurrent (dpy, win, cxVisSubThread); << 98 G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to attach a GLX context." >> 99 << G4endl; >> 100 GLint error = GL_NO_ERROR; >> 101 while ((error = glGetError()) != GL_NO_ERROR) { >> 102 G4cout << "GL Error: " << gluErrorString(error) << G4endl; >> 103 } >> 104 return; 96 } 105 } 97 G4OpenGLViewer::SetView (); << 106 G4OpenGLViewer::SetView (); 98 } 107 } 99 108 100 void G4OpenGLXViewer::ShowView () { 109 void G4OpenGLXViewer::ShowView () { 101 // glXWaitGL (); //Wait for effects of all pr << 110 glXWaitGL (); //Wait for effects of all previous OpenGL commands to 102 //be propagated before progres 111 //be propagated before progressing. 103 // JA: Commented out July 2021 - slows renderi << 104 // don't see any adverse effects. << 105 << 106 glFlush (); 112 glFlush (); 107 113 108 if (fVP.IsPicking()) { 114 if (fVP.IsPicking()) { 109 G4cout << 115 G4cout << 110 "Window activated for picking (left-mous 116 "Window activated for picking (left-mouse), exit (middle-mouse)." 111 << G4endl; 117 << G4endl; 112 while (true) { 118 while (true) { 113 if (XPending(dpy)) { 119 if (XPending(dpy)) { 114 XNextEvent(dpy, &event); 120 XNextEvent(dpy, &event); 115 if (event.type == ButtonPress && event.xbutt 121 if (event.type == ButtonPress && event.xbutton.button == 1) { 116 G4cout << Pick(event.xbutton.x, event.xbut << 122 Pick(event.xbutton.x, event.xbutton.y); 117 } 123 } 118 else if (event.type == ButtonPress && event. 124 else if (event.type == ButtonPress && event.xbutton.button == 2) break; 119 } 125 } 120 std::this_thread::sleep_for(std::chrono: << 121 } 126 } 122 } 127 } 123 } 128 } 124 129 125 void G4OpenGLXViewer::SwitchToVisSubThread() << 126 { << 127 #ifdef G4MULTITHREADED << 128 cxVisSubThread = glXCreateContext (dpy, vi, << 129 glXMakeCurrent (dpy, win, cxVisSubThread); << 130 #endif << 131 } << 132 << 133 void G4OpenGLXViewer::SwitchToMasterThread() << 134 { << 135 #ifdef G4MULTITHREADED << 136 glXMakeCurrent (dpy, win, cxMaster); << 137 // and destroy sub-thread context << 138 glXDestroyContext (dpy, cxVisSubThread); << 139 #endif << 140 } << 141 << 142 void G4OpenGLXViewer::GetXConnection () { 130 void G4OpenGLXViewer::GetXConnection () { 143 // get a connection. 131 // get a connection. 144 dpy = XOpenDisplay (0); // Uses DISPLAY env << 132 dpy = XOpenDisplay (0); 145 if (!dpy) { 133 if (!dpy) { 146 fViewId = -1; // This flags an error. 134 fViewId = -1; // This flags an error. 147 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 135 G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't open display." << G4endl; 148 return; 136 return; 149 } 137 } 150 138 151 // make sure OpenGL is supported and installed 139 // make sure OpenGL is supported and installed properly. 152 if (!glXQueryExtension (dpy, &errorBase, &ev 140 if (!glXQueryExtension (dpy, &errorBase, &eventBase)) { 153 fViewId = -1; // This flags an error. 141 fViewId = -1; // This flags an error. 154 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 142 G4cerr << "G4OpenGLViewer::G4OpenGLViewer X Server has no GLX extension." 155 << G4endl; 143 << G4endl; 156 return; 144 return; 157 } 145 } 158 146 159 } 147 } 160 148 161 void G4OpenGLXViewer::CreateGLXContext (XVisua 149 void G4OpenGLXViewer::CreateGLXContext (XVisualInfo* v) { 162 150 163 vi = v; 151 vi = v; 164 // get window's attributes 152 // get window's attributes 165 if (!XGetWindowAttributes(dpy, XRootWindow ( 153 if (!XGetWindowAttributes(dpy, XRootWindow (dpy, vi -> screen), &xwa)) { 166 fViewId = -1; // This flags an error. 154 fViewId = -1; // This flags an error. 167 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 155 G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't return window attributes" 168 << G4endl; 156 << G4endl; 169 return; 157 return; 170 } 158 } 171 159 172 // create the master GLX context << 160 // create a GLX context 173 cxMaster = glXCreateContext (dpy, vi, 0, tru << 161 cx = glXCreateContext (dpy, vi, 0, true); 174 if (!cxMaster) { << 162 if (!cx) { 175 fViewId = -1; // This flags an error. 163 fViewId = -1; // This flags an error. 176 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 164 G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't create context." 177 << G4endl; 165 << G4endl; 178 return; 166 return; 179 } 167 } 180 168 181 // New stab at getting a colormap 169 // New stab at getting a colormap 182 170 183 Status status; 171 Status status; >> 172 XStandardColormap *standardCmaps = XAllocStandardColormap (); 184 int i, numCmaps; 173 int i, numCmaps; 185 174 186 status = XmuLookupStandardColormap (dpy, 175 status = XmuLookupStandardColormap (dpy, 187 vi -> screen, 176 vi -> screen, 188 vi -> visualid, 177 vi -> visualid, 189 vi -> depth, 178 vi -> depth, 190 XA_RGB_BEST_MAP, << 179 XA_RGB_DEFAULT_MAP, 191 False, 180 False, 192 True); 181 True); 193 << 182 194 if (status == 1) { 183 if (status == 1) { 195 cmap = 0; 184 cmap = 0; 196 XStandardColormap* standardCmaps = XAllocS << 197 status = XGetRGBColormaps (dpy, 185 status = XGetRGBColormaps (dpy, 198 XRootWindow (dpy, vi -> screen), << 186 XRootWindow (dpy, vi -> screen), 199 &standardCmaps, 187 &standardCmaps, 200 &numCmaps, 188 &numCmaps, 201 XA_RGB_BEST_MAP); << 189 XA_RGB_DEFAULT_MAP); 202 if (status == 1) { << 190 if (status == 1) 203 for (i = 0; i < numCmaps; i++) { 191 for (i = 0; i < numCmaps; i++) { 204 if (standardCmaps[i].visualid == vi -> visua 192 if (standardCmaps[i].visualid == vi -> visualid) { 205 cmap = standardCmaps[i].colormap; 193 cmap = standardCmaps[i].colormap; >> 194 XFree (standardCmaps); 206 break; 195 break; 207 } 196 } 208 } 197 } >> 198 if (!cmap) { >> 199 fViewId = -1; // This flags an error. >> 200 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) >> 201 G4cerr << >> 202 "G4OpenGLViewer::G4OpenGLViewer failed to allocate a standard colormap." >> 203 << G4endl; >> 204 return; 209 } 205 } 210 XFree (standardCmaps); << 206 if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 211 if(cmap) { << 207 G4cout << "Got standard cmap" << G4endl; 212 if (G4VisManager::GetVerbosity() >= G4Vi << 213 G4cout << "Got standard cmap" << G4end << 214 } else { << 215 //if (G4VisManager::GetVerbosity() >= G4 << 216 // G4cerr << "G4OpenGLXViewer::G4OpenGL << 217 // << G4endl; << 218 cmap = XCreateColormap (dpy, << 219 XRootWindow(dpy, << 220 vi -> visual, << 221 AllocNone); << 222 if(cmap) { << 223 if (G4VisManager::GetVerbosity() >= G4 << 224 G4cout << "Created own cmap" << G4en << 225 } << 226 //G.Barrand : at end, we should do a XFr << 227 } << 228 } else { 208 } else { 229 cmap = XCreateColormap (dpy, 209 cmap = XCreateColormap (dpy, 230 XRootWindow(dpy, vi -> screen), 210 XRootWindow(dpy, vi -> screen), 231 vi -> visual, 211 vi -> visual, 232 AllocNone); 212 AllocNone); 233 if(cmap) { << 213 if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 234 if (G4VisManager::GetVerbosity() >= G4Vi << 214 G4cout << "Created own cmap" << G4endl; 235 G4cout << "Created own cmap" << G4endl << 236 } << 237 //G.Barrand : at end, we should do a XFree << 238 } 215 } 239 216 240 if (!cmap) { 217 if (!cmap) { 241 fViewId = -1; // This flags an error. 218 fViewId = -1; // This flags an error. 242 if (G4VisManager::GetVerbosity() >= G4VisM 219 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 243 G4cout << "G4OpenGLXViewer::G4OpenGLXVie << 220 G4cout << "G4OpenGLViewer::G4OpenGLViewer failed to allocate a Colormap." 244 << G4endl; 221 << G4endl; 245 return; 222 return; 246 } 223 } 247 224 248 } 225 } 249 226 250 void G4OpenGLXViewer::CreateMainWindow () { 227 void G4OpenGLXViewer::CreateMainWindow () { 251 228 252 // create a window 229 // create a window 253 swa.colormap = cmap; 230 swa.colormap = cmap; 254 swa.border_pixel = 0; 231 swa.border_pixel = 0; 255 swa.event_mask = ExposureMask | ButtonPressM 232 swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask; 256 swa.backing_store = WhenMapped; 233 swa.backing_store = WhenMapped; 257 234 258 // Window size and position... 235 // Window size and position... 259 size_hints = XAllocSizeHints(); 236 size_hints = XAllocSizeHints(); 260 237 261 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.Ge 238 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY()); 262 239 263 G4int x_origin = fVP.GetWindowAbsoluteLocati 240 G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen)); 264 241 265 // FIXME, screen size != window size on MAC 242 // FIXME, screen size != window size on MAC, but I don't know have to get the menuBar 266 // size on MAC. L.Garnier 01/2009 243 // size on MAC. L.Garnier 01/2009 267 G4int y_origin = fVP.GetWindowAbsoluteLocati 244 G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen)); 268 245 269 size_hints->base_width = getWinWidth(); 246 size_hints->base_width = getWinWidth(); 270 size_hints->base_height = getWinHeight(); 247 size_hints->base_height = getWinHeight(); 271 size_hints->x = x_origin; 248 size_hints->x = x_origin; 272 size_hints->y = y_origin; 249 size_hints->y = y_origin; 273 if (fVP.IsWindowSizeHintX () && fVP.IsWindow 250 if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { 274 size_hints->flags |= PSize | PPosition; 251 size_hints->flags |= PSize | PPosition; 275 } else if (fVP.IsWindowSizeHintX () && !(fVP 252 } else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) { 276 size_hints->flags |= PSize; 253 size_hints->flags |= PSize; 277 } else if ((!fVP.IsWindowSizeHintX ()) && fV 254 } else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { 278 size_hints->flags |= PPosition; 255 size_hints->flags |= PPosition; 279 } 256 } 280 if (G4VisManager::GetVerbosity() >= G4VisMan 257 if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 281 G4cout << "Window name: " << fName << G4en 258 G4cout << "Window name: " << fName << G4endl; 282 strncpy (charViewName, fName, 99); charViewN << 259 strncpy (charViewName, fName, 100); 283 char *window_name = charViewName; 260 char *window_name = charViewName; 284 char *icon_name = charViewName; 261 char *icon_name = charViewName; 285 //char tmpatom[] = "XA_WM_NORMAL_HINTS"; 262 //char tmpatom[] = "XA_WM_NORMAL_HINTS"; 286 wm_hints = XAllocWMHints(); 263 wm_hints = XAllocWMHints(); 287 class_hints = XAllocClassHint(); 264 class_hints = XAllocClassHint(); 288 265 289 XStringListToTextProperty (&window_name, 1, 266 XStringListToTextProperty (&window_name, 1, &windowName); 290 XStringListToTextProperty (&icon_name, 1, &i 267 XStringListToTextProperty (&icon_name, 1, &iconName); 291 268 292 wm_hints -> initial_state = NormalState; 269 wm_hints -> initial_state = NormalState; 293 wm_hints -> input = True; 270 wm_hints -> input = True; 294 wm_hints -> icon_pixmap = icon_pixmap; 271 wm_hints -> icon_pixmap = icon_pixmap; 295 wm_hints -> flags = StateHint | IconPixmapHi 272 wm_hints -> flags = StateHint | IconPixmapHint | InputHint; 296 273 297 class_hints -> res_name = NewString("G4Open 274 class_hints -> res_name = NewString("G4OpenGL"); 298 class_hints -> res_class = NewString("G4Open 275 class_hints -> res_class = NewString("G4OpenGL"); 299 276 300 win = XCreateWindow (dpy, XRootWindow (dpy, 277 win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin, 301 y_origin, getWinWidth( 278 y_origin, getWinWidth(), getWinHeight(), 0, vi -> depth, 302 InputOutput, vi -> vis 279 InputOutput, vi -> visual, 303 CWBorderPixel | CWColo 280 CWBorderPixel | CWColormap | 304 CWEventMask | CWBackin 281 CWEventMask | CWBackingStore, 305 &swa); 282 &swa); 306 283 307 XSetWMProperties (dpy, win, &windowName, &i 284 XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0, 308 size_hints, wm_hints, cla 285 size_hints, wm_hints, class_hints); 309 286 310 // request X to Draw window on screen. 287 // request X to Draw window on screen. 311 XMapWindow (dpy, win); 288 XMapWindow (dpy, win); 312 289 313 // Wait for window to appear (wait for an "exp 290 // Wait for window to appear (wait for an "expose" event). 314 XIfEvent (dpy, &event, G4OpenGLXViewerWaitFo 291 XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win); 315 292 316 // connect the context to a window 293 // connect the context to a window 317 Bool success = glXMakeCurrent (dpy, win, cxM << 294 Bool success = glXMakeCurrent (dpy, win, cx); 318 if (!success) { 295 if (!success) { 319 fViewId = -1; // This flags an error. 296 fViewId = -1; // This flags an error. 320 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 297 G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to attach a GLX context." 321 << G4endl; 298 << G4endl; 322 GLint error = GL_NO_ERROR; 299 GLint error = GL_NO_ERROR; 323 while ((error = glGetError()) != GL_NO_ERR 300 while ((error = glGetError()) != GL_NO_ERROR) { 324 switch (error) { << 301 G4cout << "GL Error: " << gluErrorString(error) << G4endl; 325 case GL_INVALID_ENUM : << 326 G4cout << "GL Error: GL_INVALID_ENUM" << G4e << 327 case GL_INVALID_VALUE : << 328 G4cout << "GL Error: GL_INVALID_VALUE" << G4 << 329 case GL_INVALID_OPERATION : << 330 G4cout << "GL Error: GL_INVALID_OPERATION" < << 331 case GL_OUT_OF_MEMORY : << 332 G4cout << "GL Error: GL_OUT_OF_MEMORY" << G4 << 333 case GL_STACK_UNDERFLOW : << 334 G4cout << "GL Error: GL_STACK_UNDERFLOW" << << 335 case GL_STACK_OVERFLOW : << 336 G4cout << "GL Error: GL_STACK_OVERFLOW" << G << 337 default : << 338 G4cout << "GL Error: " << error << G4endl;br << 339 } << 340 } 302 } 341 return; 303 return; 342 } 304 } >> 305 343 } 306 } 344 307 345 void G4OpenGLXViewer::CreateFontLists() << 308 void G4OpenGLXViewer::CreateFontLists () { 346 { << 309 347 std::map<G4double,G4String> fonts; // G4VMa 310 std::map<G4double,G4String> fonts; // G4VMarker screen size and font name. 348 fonts[10.] = "-adobe-courier-bold-r-normal-- 311 fonts[10.] = "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1"; 349 fonts[11.] = "-adobe-courier-bold-r-normal-- 312 fonts[11.] = "-adobe-courier-bold-r-normal--11-80-100-100-m-60-iso8859-1"; 350 fonts[12.] = "-adobe-courier-bold-r-normal-- 313 fonts[12.] = "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1"; 351 fonts[13.] = "fixed"; 314 fonts[13.] = "fixed"; 352 fonts[14.] = "-adobe-courier-bold-r-normal-- 315 fonts[14.] = "-adobe-courier-bold-r-normal--14-100-100-100-m-90-iso8859-1"; 353 fonts[17.] = "-adobe-courier-bold-r-normal-- 316 fonts[17.] = "-adobe-courier-bold-r-normal--17-120-100-100-m-100-iso8859-1"; 354 fonts[18.] = "-adobe-courier-bold-r-normal-- 317 fonts[18.] = "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1"; 355 fonts[20.] = "-adobe-courier-bold-r-normal-- 318 fonts[20.] = "-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1"; 356 fonts[24.] = "-adobe-courier-bold-r-normal-- 319 fonts[24.] = "-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1"; 357 fonts[25.] = "-adobe-courier-bold-r-normal-- 320 fonts[25.] = "-adobe-courier-bold-r-normal--25-180-100-100-m-150-iso8859-1"; 358 fonts[34.] = "-adobe-courier-bold-r-normal-- 321 fonts[34.] = "-adobe-courier-bold-r-normal--34-240-100-100-m-200-iso8859-1"; 359 std::map<G4double,G4String>::const_iterator 322 std::map<G4double,G4String>::const_iterator i; 360 for (i = fonts.begin(); i != fonts.end(); ++ 323 for (i = fonts.begin(); i != fonts.end(); ++i) { 361 XFontStruct* font_info = XLoadQueryFont(dp 324 XFontStruct* font_info = XLoadQueryFont(dpy, i->second); 362 if (!font_info) { 325 if (!font_info) { 363 G4cerr << 326 G4cerr << 364 "G4OpenGLXViewer::CreateFontLists XLoadQuery << 327 "G4OpenGLXViewer: XLoadQueryFont failed for font\n " 365 << i->second 328 << i->second 366 << G4endl; 329 << G4endl; 367 continue; 330 continue; 368 } 331 } 369 G4int font_base = glGenLists(256); 332 G4int font_base = glGenLists(256); 370 if (!font_base) { 333 if (!font_base) { 371 G4cerr << << 334 G4cerr << "G4OpenGLXViewer: out of display lists for fonts." 372 "G4OpenGLXViewer::CreateFontLists out of dis << 373 << G4endl; 335 << G4endl; 374 continue; 336 continue; 375 } 337 } 376 G4int first = font_info->min_char_or_byte2 338 G4int first = font_info->min_char_or_byte2; 377 G4int last = font_info->max_char_or_byte2 339 G4int last = font_info->max_char_or_byte2; 378 glXUseXFont(font_info->fid, first, last-fi << 340 glXUseXFont(font_info->fid, first, last-first+1,font_base+first); 379 G4int width = font_info->max_bounds.width; << 341 G4OpenGLFontBaseStore::AddFontBase(this,font_base,i->first,i->second); 380 G4OpenGLFontBaseStore::AddFontBase << 381 (this, font_base, i->first, i->second, w << 382 } << 383 } << 384 << 385 void G4OpenGLXViewer::DrawText(const G4Text& g << 386 { << 387 if (isGl2psWriting()) { << 388 << 389 G4OpenGLViewer::DrawText(g4text); << 390 << 391 } else { << 392 << 393 G4VSceneHandler::MarkerSizeType sizeType; << 394 G4double size = fSceneHandler.GetMarkerSiz << 395 << 396 const G4OpenGLFontBaseStore::FontInfo& fon << 397 G4OpenGLFontBaseStore::GetFontInfo(this, << 398 if (fontInfo.fFontBase < 0) { << 399 static G4int callCount = 0; << 400 ++callCount; << 401 //if (callCount <= 10 || callCount%100 = << 402 if (callCount <= 1) { << 403 G4cout << << 404 "G4OpenGLXViewer::DrawText: No fonts avail << 405 << fName << << 406 "\"\n Called with " << 407 << g4text << 408 << G4endl; << 409 } << 410 return; << 411 } << 412 << 413 const G4Colour& c = fSceneHandler.GetTextC << 414 glColor4d(c.GetRed(),c.GetGreen(),c.GetBlu << 415 << 416 G4Point3D position = g4text.GetPosition(); << 417 << 418 G4String textString = g4text.GetText(); << 419 const char* textCString = textString.c_str << 420 << 421 // Set position for raster-style drawers ( << 422 glRasterPos3d(position.x(),position.y(),po << 423 << 424 glPushAttrib(GL_LIST_BIT); << 425 << 426 // Calculate move for centre and right adj << 427 G4double span = textString.size() * fontIn << 428 G4double xmove = 0., ymove = 0.; << 429 switch (g4text.GetLayout()) { << 430 case G4Text::left: break; << 431 case G4Text::centre: xmove -= span / 2.; b << 432 case G4Text::right: xmove -= span; << 433 } << 434 << 435 //Add offsets << 436 xmove += g4text.GetXOffset(); << 437 ymove += g4text.GetYOffset(); << 438 << 439 // Do move << 440 glBitmap(0,0,0,0,xmove,ymove,0); << 441 << 442 // Write characters << 443 glListBase(fontInfo.fFontBase); << 444 glCallLists((G4int)strlen(textCString),GL_ << 445 glPopAttrib(); << 446 } 342 } 447 } 343 } 448 344 449 << 450 G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLScen 345 G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLSceneHandler& scene): 451 G4VViewer (scene, -1), 346 G4VViewer (scene, -1), 452 G4OpenGLViewer (scene), 347 G4OpenGLViewer (scene), 453 vi_immediate (0), 348 vi_immediate (0), 454 vi_stored (0), 349 vi_stored (0), 455 vi (0), 350 vi (0), 456 cmap (0) 351 cmap (0) 457 { 352 { 458 // To satisfy Coverity << 459 xwa.visual = 0; << 460 iconName.value = 0; << 461 xwa.screen = 0; << 462 windowName.value = 0; << 463 << 464 GetXConnection (); 353 GetXConnection (); 465 if (fViewId < 0) return; 354 if (fViewId < 0) return; 466 355 467 // Try for a visual suitable for OpenGLImmed 356 // Try for a visual suitable for OpenGLImmediate.. 468 // first try for a single buffered RGB windo 357 // first try for a single buffered RGB window 469 if (!vi_single_buffer) { 358 if (!vi_single_buffer) { 470 vi_single_buffer = 359 vi_single_buffer = 471 glXChooseVisual (dpy, XDefaultScreen (dp 360 glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA); 472 //G.Barrand : we should do a XFree(vi_sing << 473 } 361 } 474 if (!vi_double_buffer) { 362 if (!vi_double_buffer) { 475 vi_double_buffer = 363 vi_double_buffer = 476 glXChooseVisual (dpy, XDefaultScreen (dp 364 glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA); 477 //G.Barrand : we should do a XFree(vi_doub << 478 } 365 } 479 366 480 if (vi_single_buffer || vi_double_buffer) { 367 if (vi_single_buffer || vi_double_buffer) { 481 if (!vi_double_buffer) { 368 if (!vi_double_buffer) { 482 G4cout << 369 G4cout << 483 "G4OpenGLXViewer::G4OpenGLXViewer: unable to 370 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual." 484 "\n Working with a single buffer." 371 "\n Working with a single buffer." 485 << G4endl; 372 << G4endl; 486 } 373 } 487 } else { 374 } else { 488 if (!vi_single_buffer) { 375 if (!vi_single_buffer) { 489 G4cout << 376 G4cout << 490 "G4OpenGLXViewer::G4OpenGLXViewer: unable to 377 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a single buffer visual." 491 << G4endl; 378 << G4endl; 492 } 379 } 493 if (!vi_double_buffer) { 380 if (!vi_double_buffer) { 494 G4cout << 381 G4cout << 495 "G4OpenGLXViewer::G4OpenGLXViewer: unable to 382 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual." 496 << G4endl; 383 << G4endl; 497 } 384 } 498 } 385 } 499 386 500 if (vi_single_buffer) { 387 if (vi_single_buffer) { 501 vi_immediate = vi_single_buffer; 388 vi_immediate = vi_single_buffer; 502 attributeList = snglBuf_RGBA; 389 attributeList = snglBuf_RGBA; 503 } 390 } 504 391 505 if (!vi_immediate){ 392 if (!vi_immediate){ 506 // next try for a double buffered RGB, but 393 // next try for a double buffered RGB, but Draw to top buffer 507 if (vi_double_buffer) { 394 if (vi_double_buffer) { 508 vi_immediate = vi_double_buffer; 395 vi_immediate = vi_double_buffer; 509 attributeList = dblBuf_RGBA; 396 attributeList = dblBuf_RGBA; 510 } 397 } 511 } 398 } 512 399 513 // Now try for a visual suitable for OpenGLS 400 // Now try for a visual suitable for OpenGLStored... 514 // Try for a double buffered RGB window 401 // Try for a double buffered RGB window 515 if (vi_double_buffer) { 402 if (vi_double_buffer) { 516 vi_stored = vi_double_buffer; 403 vi_stored = vi_double_buffer; 517 attributeList = dblBuf_RGBA; 404 attributeList = dblBuf_RGBA; 518 } 405 } 519 406 520 if (!vi_immediate || !vi_stored) { 407 if (!vi_immediate || !vi_stored) { 521 G4cout << 408 G4cout << 522 "G4OpenGLXViewer::G4OpenGLXViewer: unable 409 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get required visuals." 523 << G4endl; 410 << G4endl; 524 fViewId = -1; // This flags an error. 411 fViewId = -1; // This flags an error. 525 } 412 } 526 413 527 // glClearColor (0., 0., 0., 0.); 414 // glClearColor (0., 0., 0., 0.); 528 // glClearDepth (1.); 415 // glClearDepth (1.); 529 } 416 } 530 417 531 G4OpenGLXViewer::~G4OpenGLXViewer () { 418 G4OpenGLXViewer::~G4OpenGLXViewer () { 532 if (fViewId >= 0) { 419 if (fViewId >= 0) { 533 //Close a window from here 420 //Close a window from here 534 glXMakeCurrent (dpy, None, NULL); 421 glXMakeCurrent (dpy, None, NULL); 535 glXDestroyContext (dpy, cxMaster); << 422 glXDestroyContext (dpy, cx); 536 if (win) XDestroyWindow (dpy, win); // ... 423 if (win) XDestroyWindow (dpy, win); // ...if already deleted in 537 // sub-class G4OpenGLXmViewer. 424 // sub-class G4OpenGLXmViewer. 538 // We should do a XFreeColormap(dpy,cmap); << 539 XFlush (dpy); 425 XFlush (dpy); 540 } 426 } 541 } 427 } 542 428 >> 429 >> 430 #endif 543 431