Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenGL/src/G4OpenGLXViewer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenGL/src/G4OpenGLXViewer.cc (Version 11.3.0) and /visualization/OpenGL/src/G4OpenGLXViewer.cc (Version 9.3.p1)


  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.55 2009/05/13 10:28:00 lgarnier Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-03-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"                     << 
 45 #include "G4Text.hh"                           << 
 46 #include "G4Threading.hh"                      << 
 47                                                    52 
 48 #include <X11/Xatom.h>                             53 #include <X11/Xatom.h>
 49 #include <X11/Xutil.h>                             54 #include <X11/Xutil.h>
 50 #include <X11/Xmu/StdCmap.h>                       55 #include <X11/Xmu/StdCmap.h>
 51                                                    56 
 52 #include <assert.h>                                57 #include <assert.h>
 53 #include <sstream>                             << 
 54 #include <chrono>                              << 
 55 #include <thread>                              << 
 56                                                    58 
 57 int G4OpenGLXViewer::snglBuf_RGBA[12] =            59 int G4OpenGLXViewer::snglBuf_RGBA[12] =
 58 { GLX_RGBA,                                        60 { GLX_RGBA,
 59   GLX_RED_SIZE, 1,                                 61   GLX_RED_SIZE, 1,
 60   GLX_GREEN_SIZE, 1,                               62   GLX_GREEN_SIZE, 1, 
 61   GLX_BLUE_SIZE, 1,                                63   GLX_BLUE_SIZE, 1,
 62   GLX_DEPTH_SIZE, 1,                               64   GLX_DEPTH_SIZE, 1,
 63   GLX_STENCIL_SIZE, 1,                             65   GLX_STENCIL_SIZE, 1,
 64   None };                                          66   None };
 65                                                    67 
 66 int G4OpenGLXViewer::dblBuf_RGBA[13] =             68 int G4OpenGLXViewer::dblBuf_RGBA[13] =
 67 { GLX_RGBA,                                        69 { GLX_RGBA,
 68   GLX_RED_SIZE, 1,                                 70   GLX_RED_SIZE, 1,
 69   GLX_GREEN_SIZE, 1,                               71   GLX_GREEN_SIZE, 1,
 70   GLX_BLUE_SIZE, 1,                                72   GLX_BLUE_SIZE, 1,
 71   GLX_DOUBLEBUFFER,                                73   GLX_DOUBLEBUFFER,
 72   GLX_DEPTH_SIZE, 1,                               74   GLX_DEPTH_SIZE, 1,
 73   GLX_STENCIL_SIZE, 1,                             75   GLX_STENCIL_SIZE, 1,
 74   None };                                          76   None };
 75                                                    77 
 76 #define NewString(str) \                           78 #define NewString(str) \
 77   ((str) != 0 ? (strncpy((char*)malloc((unsign <<  79  ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
 78                                                    80 
 79 #define USE_DEFAULT_COLORMAP 1                     81 #define USE_DEFAULT_COLORMAP 1
 80 #define USE_STANDARD_COLORMAP 0                    82 #define USE_STANDARD_COLORMAP 0
 81                                                    83 
 82 XVisualInfo*  G4OpenGLXViewer::vi_single_buffe     84 XVisualInfo*  G4OpenGLXViewer::vi_single_buffer = 0;
 83 XVisualInfo*  G4OpenGLXViewer::vi_double_buffe     85 XVisualInfo*  G4OpenGLXViewer::vi_double_buffer = 0;
 84                                                    86 
 85 extern "C" {                                       87 extern "C" {
 86   static Bool G4OpenGLXViewerWaitForNotify (Di     88   static Bool G4OpenGLXViewerWaitForNotify (Display*, XEvent* e, char* arg) {
 87     return (e->type == MapNotify) && (e->xmap.     89     return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
 88   }                                                90   }
 89 }                                                  91 }
 90                                                    92 
 91 void G4OpenGLXViewer::SetView () {                 93 void G4OpenGLXViewer::SetView () {
 92   if (G4Threading::IsMasterThread()) {         <<  94   Bool success = glXMakeCurrent (dpy, win, cx);
 93     glXMakeCurrent (dpy, win, cxMaster);       <<  95   if (!success) {
 94   } else {                                     <<  96     fViewId = -1;  // This flags an error.
 95     glXMakeCurrent (dpy, win, cxVisSubThread); <<  97     G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to attach a GLX context."
                                                   >>  98            << G4endl;
                                                   >>  99     GLint error = GL_NO_ERROR;
                                                   >> 100     while ((error = glGetError()) != GL_NO_ERROR) {
                                                   >> 101       G4cout << "GL Error: " << gluErrorString(error) << G4endl;
                                                   >> 102     }
                                                   >> 103     return;
 96   }                                               104   }
 97   G4OpenGLViewer::SetView ();                  << 105   G4OpenGLViewer::SetView ();  
 98 }                                                 106 }
 99                                                   107 
100 void G4OpenGLXViewer::ShowView () {               108 void G4OpenGLXViewer::ShowView () {
101 //  glXWaitGL (); //Wait for effects of all pr << 109   glXWaitGL (); //Wait for effects of all previous OpenGL commands to
102                 //be propagated before progres    110                 //be propagated before progressing.
103 // JA: Commented out July 2021 - slows renderi << 
104 // don't see any adverse effects.              << 
105                                                << 
106   glFlush ();                                     111   glFlush ();
107                                                   112 
108   if (fVP.IsPicking()) {                          113   if (fVP.IsPicking()) {
109     G4cout <<                                     114     G4cout <<
110       "Window activated for picking (left-mous    115       "Window activated for picking (left-mouse), exit (middle-mouse)."
111      << G4endl;                                   116      << G4endl;
112     while (true) {                                117     while (true) {
113       if (XPending(dpy)) {                        118       if (XPending(dpy)) {
114   XNextEvent(dpy, &event);                        119   XNextEvent(dpy, &event);
115   if (event.type == ButtonPress && event.xbutt    120   if (event.type == ButtonPress && event.xbutton.button == 1) {
116     G4cout << Pick(event.xbutton.x, event.xbut << 121     Pick(event.xbutton.x, event.xbutton.y);
117   }                                               122   }
118   else if (event.type == ButtonPress && event.    123   else if (event.type == ButtonPress && event.xbutton.button == 2) break;
119       }                                           124       }
120       std::this_thread::sleep_for(std::chrono: << 
121     }                                             125     }
122   }                                               126   }
123 }                                                 127 }
124                                                   128 
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 () {         129 void G4OpenGLXViewer::GetXConnection () {
143 // get a connection.                              130 // get a connection.
144   dpy = XOpenDisplay (0);  // Uses DISPLAY env << 131   dpy = XOpenDisplay (0);
145   if (!dpy) {                                     132   if (!dpy) {
146     fViewId = -1;  // This flags an error.        133     fViewId = -1;  // This flags an error.
147     G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 134     G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't open display." << G4endl;
148     return;                                       135     return;
149   }                                               136   }
150                                                   137 
151 // make sure OpenGL is supported and installed    138 // make sure OpenGL is supported and installed properly.
152   if (!glXQueryExtension (dpy, &errorBase, &ev    139   if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
153     fViewId = -1;  // This flags an error.        140     fViewId = -1;  // This flags an error.
154     G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 141     G4cerr << "G4OpenGLViewer::G4OpenGLViewer X Server has no GLX extension." 
155    << G4endl;                                     142    << G4endl;
156     return;                                       143     return;
157   }                                               144   }
158                                                   145 
159 }                                                 146 }
160                                                   147 
161 void G4OpenGLXViewer::CreateGLXContext (XVisua    148 void G4OpenGLXViewer::CreateGLXContext (XVisualInfo* v) {
162                                                   149 
163   vi = v;                                         150   vi = v;
164 // get window's attributes                        151 // get window's attributes
165   if (!XGetWindowAttributes(dpy, XRootWindow (    152   if (!XGetWindowAttributes(dpy, XRootWindow (dpy, vi -> screen), &xwa)) {
166     fViewId = -1;  // This flags an error.        153     fViewId = -1;  // This flags an error.
167     G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 154     G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't return window attributes"
168    << G4endl;                                     155    << G4endl;
169     return;                                       156     return;
170   }                                               157   }
171                                                   158   
172 // create the master GLX context               << 159 // create a GLX context
173   cxMaster = glXCreateContext (dpy, vi, 0, tru << 160   cx = glXCreateContext (dpy, vi, 0, true);
174   if (!cxMaster) {                             << 161   if (!cx) {
175     fViewId = -1;  // This flags an error.        162     fViewId = -1;  // This flags an error.
176     G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 163     G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't create context."
177    << G4endl;                                     164    << G4endl;
178     return;                                       165     return;
179   }                                               166   }
180                                                   167 
181 // New stab at getting a colormap                 168 // New stab at getting a colormap
182                                                   169 
183   Status status;                                  170   Status status;
                                                   >> 171   XStandardColormap *standardCmaps = XAllocStandardColormap ();
184   int i, numCmaps;                                172   int i, numCmaps;
185                                                   173 
186   status = XmuLookupStandardColormap (dpy,        174   status = XmuLookupStandardColormap (dpy, 
187               vi -> screen,                       175               vi -> screen, 
188               vi -> visualid,                     176               vi -> visualid, 
189               vi -> depth,                        177               vi -> depth, 
190               XA_RGB_BEST_MAP,                 << 178               XA_RGB_DEFAULT_MAP, 
191               False,                              179               False, 
192               True);                              180               True);
193                                                << 181   
194   if (status == 1) {                              182   if (status == 1) {
195     cmap = 0;                                     183     cmap = 0;
196     XStandardColormap* standardCmaps = XAllocS << 
197     status = XGetRGBColormaps (dpy,               184     status = XGetRGBColormaps (dpy, 
198              XRootWindow (dpy, vi -> screen),  << 185              XRootWindow (dpy, vi -> screen), 
199              &standardCmaps,                      186              &standardCmaps, 
200              &numCmaps,                           187              &numCmaps, 
201              XA_RGB_BEST_MAP);                 << 188              XA_RGB_DEFAULT_MAP);
202     if (status == 1) {                         << 189     if (status == 1)
203       for (i = 0; i < numCmaps; i++) {            190       for (i = 0; i < numCmaps; i++) {
204   if (standardCmaps[i].visualid == vi -> visua    191   if (standardCmaps[i].visualid == vi -> visualid) {
205     cmap = standardCmaps[i].colormap;             192     cmap = standardCmaps[i].colormap;
                                                   >> 193     XFree (standardCmaps);
206     break;                                        194     break;
207   }                                               195   }
208       }                                           196       }
                                                   >> 197     if (!cmap) {
                                                   >> 198       fViewId = -1;  // This flags an error.
                                                   >> 199       G4cerr <<
                                                   >> 200    "G4OpenGLViewer::G4OpenGLViewer failed to allocate a standard colormap."
                                                   >> 201        << G4endl;
                                                   >> 202       return;
209     }                                             203     }
210     XFree (standardCmaps);                     << 204     G4cout << "Got standard cmap" << G4endl;
211     if(cmap) {                                 << 
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 {                                        205   } else {
229     cmap = XCreateColormap (dpy,                  206     cmap = XCreateColormap (dpy, 
230           XRootWindow(dpy, vi -> screen),         207           XRootWindow(dpy, vi -> screen), 
231           vi -> visual,                           208           vi -> visual, 
232           AllocNone);                             209           AllocNone);
233     if(cmap) {                                 << 210     G4cout << "Created own cmap" << G4endl;
234       if (G4VisManager::GetVerbosity() >= G4Vi << 
235         G4cout << "Created own cmap" << G4endl << 
236     }                                          << 
237     //G.Barrand : at end, we should do a XFree << 
238   }                                               211   }
239                                                   212 
240   if (!cmap) {                                    213   if (!cmap) {
241     fViewId = -1;  // This flags an error.        214     fViewId = -1;  // This flags an error.
242     if (G4VisManager::GetVerbosity() >= G4VisM << 215     G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to allocate a Colormap."
243       G4cout << "G4OpenGLXViewer::G4OpenGLXVie << 216    << G4endl;
244        << G4endl;                              << 
245     return;                                       217     return;
246   }                                               218   }
247                                                   219 
248 }                                                 220 }
249                                                   221   
250 void G4OpenGLXViewer::CreateMainWindow () {       222 void G4OpenGLXViewer::CreateMainWindow () {
251                                                   223   
252 // create a window                                224 // create a window
253   swa.colormap = cmap;                            225   swa.colormap = cmap;
254   swa.border_pixel = 0;                           226   swa.border_pixel = 0;
255   swa.event_mask = ExposureMask | ButtonPressM    227   swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
256   swa.backing_store = WhenMapped;                 228   swa.backing_store = WhenMapped;
257                                                   229 
258   // Window size and position...                  230   // Window size and position...
259   size_hints = XAllocSizeHints();                 231   size_hints = XAllocSizeHints();
260                                                   232     
261   ResizeWindow(fVP.GetWindowSizeHintX(),fVP.Ge    233   ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
262                                                   234 
263   G4int x_origin = fVP.GetWindowAbsoluteLocati    235   G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen));
264                                                   236 
265   // FIXME,  screen size != window size on MAC    237   // 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               238   // size on MAC. L.Garnier 01/2009
267   G4int y_origin = fVP.GetWindowAbsoluteLocati    239   G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen));
268                                                   240 
269   size_hints->base_width = getWinWidth();         241   size_hints->base_width = getWinWidth();
270   size_hints->base_height = getWinHeight();       242   size_hints->base_height = getWinHeight();
271   size_hints->x = x_origin;                       243   size_hints->x = x_origin;
272   size_hints->y = y_origin;                       244   size_hints->y = y_origin;
273   if (fVP.IsWindowSizeHintX () && fVP.IsWindow    245   if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
274     size_hints->flags |= PSize | PPosition;       246     size_hints->flags |= PSize | PPosition;
275   } else if (fVP.IsWindowSizeHintX () && !(fVP    247   } else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) {
276     size_hints->flags |= PSize;                   248     size_hints->flags |= PSize;
277   } else if ((!fVP.IsWindowSizeHintX ()) && fV    249   } else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
278     size_hints->flags |= PPosition;               250     size_hints->flags |= PPosition;
279   }                                               251   }
280   if (G4VisManager::GetVerbosity() >= G4VisMan << 252   G4cout << "Window name: " << fName << G4endl;
281     G4cout << "Window name: " << fName << G4en << 253   strncpy (charViewName, fName, 100);
282   strncpy (charViewName, fName, 99); charViewN << 
283   char *window_name = charViewName;               254   char *window_name = charViewName;
284   char *icon_name = charViewName;                 255   char *icon_name = charViewName;
285   //char tmpatom[] = "XA_WM_NORMAL_HINTS";        256   //char tmpatom[] = "XA_WM_NORMAL_HINTS"; 
286   wm_hints = XAllocWMHints();                     257   wm_hints = XAllocWMHints();
287   class_hints = XAllocClassHint();                258   class_hints = XAllocClassHint();
288                                                   259 
289   XStringListToTextProperty (&window_name, 1,     260   XStringListToTextProperty (&window_name, 1, &windowName);
290   XStringListToTextProperty (&icon_name, 1, &i    261   XStringListToTextProperty (&icon_name, 1, &iconName);
291                                                   262 
292   wm_hints -> initial_state = NormalState;        263   wm_hints -> initial_state = NormalState;
293   wm_hints -> input = True;                       264   wm_hints -> input = True;
294   wm_hints -> icon_pixmap = icon_pixmap;          265   wm_hints -> icon_pixmap = icon_pixmap;
295   wm_hints -> flags = StateHint | IconPixmapHi    266   wm_hints -> flags = StateHint | IconPixmapHint | InputHint;
296                                                   267 
297   class_hints -> res_name  = NewString("G4Open    268   class_hints -> res_name  = NewString("G4OpenGL");
298   class_hints -> res_class = NewString("G4Open    269   class_hints -> res_class = NewString("G4OpenGL");
299                                                   270 
300    win = XCreateWindow (dpy, XRootWindow (dpy,    271    win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin, 
301                         y_origin, getWinWidth(    272                         y_origin, getWinWidth(), getWinHeight(), 0, vi -> depth,
302                         InputOutput, vi -> vis    273                         InputOutput, vi -> visual,  
303                         CWBorderPixel | CWColo    274                         CWBorderPixel | CWColormap | 
304                         CWEventMask | CWBackin    275                         CWEventMask | CWBackingStore,
305                         &swa);                    276                         &swa);
306                                                   277   
307    XSetWMProperties (dpy, win, &windowName, &i    278    XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0, 
308                      size_hints, wm_hints, cla    279                      size_hints, wm_hints, class_hints);
309                                                   280   
310 // request X to Draw window on screen.            281 // request X to Draw window on screen.
311   XMapWindow (dpy, win);                          282   XMapWindow (dpy, win);
312                                                   283 
313 // Wait for window to appear (wait for an "exp    284 // Wait for window to appear (wait for an "expose" event).
314   XIfEvent (dpy, &event, G4OpenGLXViewerWaitFo    285   XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win);
315                                                   286 
316 // connect the context to a window                287 // connect the context to a window
317   Bool success = glXMakeCurrent (dpy, win, cxM << 288   Bool success = glXMakeCurrent (dpy, win, cx);
318   if (!success) {                                 289   if (!success) {
319     fViewId = -1;  // This flags an error.        290     fViewId = -1;  // This flags an error.
320     G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe << 291     G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to attach a GLX context."
321    << G4endl;                                     292    << G4endl;
322     GLint error = GL_NO_ERROR;                    293     GLint error = GL_NO_ERROR;
323     while ((error = glGetError()) != GL_NO_ERR    294     while ((error = glGetError()) != GL_NO_ERROR) {
324       switch (error) {                         << 295       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     }                                             296     }
341     return;                                       297     return;
342   }                                               298   }
                                                   >> 299 
343 }                                                 300 }
344                                                   301 
345 void G4OpenGLXViewer::CreateFontLists()        << 302 void G4OpenGLXViewer::CreateFontLists () {
346 {                                              << 303 
347   std::map<G4double,G4String> fonts;  // G4VMa    304   std::map<G4double,G4String> fonts;  // G4VMarker screen size and font name.
348   fonts[10.] = "-adobe-courier-bold-r-normal--    305   fonts[10.] = "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1";
349   fonts[11.] = "-adobe-courier-bold-r-normal--    306   fonts[11.] = "-adobe-courier-bold-r-normal--11-80-100-100-m-60-iso8859-1";
350   fonts[12.] = "-adobe-courier-bold-r-normal--    307   fonts[12.] = "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1";
351   fonts[13.] = "fixed";                           308   fonts[13.] = "fixed";
352   fonts[14.] = "-adobe-courier-bold-r-normal--    309   fonts[14.] = "-adobe-courier-bold-r-normal--14-100-100-100-m-90-iso8859-1";
353   fonts[17.] = "-adobe-courier-bold-r-normal--    310   fonts[17.] = "-adobe-courier-bold-r-normal--17-120-100-100-m-100-iso8859-1";
354   fonts[18.] = "-adobe-courier-bold-r-normal--    311   fonts[18.] = "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1";
355   fonts[20.] = "-adobe-courier-bold-r-normal--    312   fonts[20.] = "-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1";
356   fonts[24.] = "-adobe-courier-bold-r-normal--    313   fonts[24.] = "-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1";
357   fonts[25.] = "-adobe-courier-bold-r-normal--    314   fonts[25.] = "-adobe-courier-bold-r-normal--25-180-100-100-m-150-iso8859-1";
358   fonts[34.] = "-adobe-courier-bold-r-normal--    315   fonts[34.] = "-adobe-courier-bold-r-normal--34-240-100-100-m-200-iso8859-1";
359   std::map<G4double,G4String>::const_iterator     316   std::map<G4double,G4String>::const_iterator i;
360   for (i = fonts.begin(); i != fonts.end(); ++    317   for (i = fonts.begin(); i != fonts.end(); ++i) {
361     XFontStruct* font_info = XLoadQueryFont(dp    318     XFontStruct* font_info = XLoadQueryFont(dpy, i->second);
362     if (!font_info) {                             319     if (!font_info) {
363       G4cerr <<                                   320       G4cerr <<
364   "G4OpenGLXViewer::CreateFontLists XLoadQuery << 321   "G4OpenGLXViewer: XLoadQueryFont failed for font\n  "
365        << i->second                               322        << i->second
366        << G4endl;                                 323        << G4endl;
367       continue;                                   324       continue;
368     }                                             325     }
369     G4int font_base = glGenLists(256);            326     G4int font_base = glGenLists(256);
370     if (!font_base) {                             327     if (!font_base) {
371       G4cerr <<                                << 328       G4cerr << "G4OpenGLXViewer: out of display lists for fonts." 
372   "G4OpenGLXViewer::CreateFontLists out of dis << 
373        << G4endl;                                 329        << G4endl;
374       continue;                                   330       continue;
375     }                                             331     }
376     G4int first = font_info->min_char_or_byte2    332     G4int first = font_info->min_char_or_byte2;
377     G4int last  = font_info->max_char_or_byte2    333     G4int last  = font_info->max_char_or_byte2;
378     glXUseXFont(font_info->fid, first, last-fi << 334     glXUseXFont(font_info->fid, first, last-first+1,font_base+first);
379     G4int width = font_info->max_bounds.width; << 335     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   }                                               336   }
447 }                                                 337 }
448                                                   338 
449                                                << 
450 G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLScen    339 G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLSceneHandler& scene):
451 G4VViewer (scene, -1),                            340 G4VViewer (scene, -1),
452 G4OpenGLViewer (scene),                           341 G4OpenGLViewer (scene),
453 vi_immediate (0),                                 342 vi_immediate (0),
454 vi_stored (0),                                    343 vi_stored (0),
455 vi (0),                                           344 vi (0),
456 cmap (0)                                          345 cmap (0)
457 {                                                 346 {
458   // To satisfy Coverity                       << 
459   xwa.visual = 0;                              << 
460   iconName.value = 0;                          << 
461   xwa.screen = 0;                              << 
462   windowName.value = 0;                        << 
463                                                << 
464   GetXConnection ();                              347   GetXConnection ();
465   if (fViewId < 0) return;                        348   if (fViewId < 0) return;
466                                                   349   
467   // Try for a visual suitable for OpenGLImmed    350   // Try for a visual suitable for OpenGLImmediate..
468   // first try for a single buffered RGB windo    351   // first try for a single buffered RGB window
469   if (!vi_single_buffer) {                        352   if (!vi_single_buffer) {
470     vi_single_buffer =                            353     vi_single_buffer =
471       glXChooseVisual (dpy, XDefaultScreen (dp    354       glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA);
472     //G.Barrand : we should do a XFree(vi_sing << 
473   }                                               355   }
474   if (!vi_double_buffer) {                        356   if (!vi_double_buffer) {
475     vi_double_buffer =                            357     vi_double_buffer =
476       glXChooseVisual (dpy, XDefaultScreen (dp    358       glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA);
477     //G.Barrand : we should do a XFree(vi_doub << 
478   }                                               359   }
479                                                   360 
480   if (vi_single_buffer || vi_double_buffer) {     361   if (vi_single_buffer || vi_double_buffer) {
481     if (!vi_double_buffer) {                      362     if (!vi_double_buffer) {
482       G4cout <<                                   363       G4cout <<
483   "G4OpenGLXViewer::G4OpenGLXViewer: unable to    364   "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
484   "\n  Working with a single buffer."             365   "\n  Working with a single buffer."
485        << G4endl;                                 366        << G4endl;
486     }                                             367     }
487   } else {                                        368   } else {
488     if (!vi_single_buffer) {                      369     if (!vi_single_buffer) {
489       G4cout <<                                   370       G4cout <<
490   "G4OpenGLXViewer::G4OpenGLXViewer: unable to    371   "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a single buffer visual."
491        << G4endl;                                 372        << G4endl;
492     }                                             373     }
493     if (!vi_double_buffer) {                      374     if (!vi_double_buffer) {
494       G4cout <<                                   375       G4cout <<
495   "G4OpenGLXViewer::G4OpenGLXViewer: unable to    376   "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
496        << G4endl;                                 377        << G4endl;
497     }                                             378     }
498   }                                               379   }
499                                                   380 
500   if (vi_single_buffer) {                         381   if (vi_single_buffer) {
501     vi_immediate = vi_single_buffer;              382     vi_immediate = vi_single_buffer;
502     attributeList = snglBuf_RGBA;                 383     attributeList = snglBuf_RGBA;
503   }                                               384   }
504                                                   385   
505   if (!vi_immediate){                             386   if (!vi_immediate){
506     // next try for a double buffered RGB, but    387     // next try for a double buffered RGB, but Draw to top buffer
507     if (vi_double_buffer) {                       388     if (vi_double_buffer) {
508       vi_immediate = vi_double_buffer;            389       vi_immediate = vi_double_buffer;
509       attributeList = dblBuf_RGBA;                390       attributeList = dblBuf_RGBA;
510     }                                             391     }
511   }                                               392   }
512                                                   393 
513   // Now try for a visual suitable for OpenGLS    394   // Now try for a visual suitable for OpenGLStored...
514   // Try for a double buffered RGB window         395   // Try for a double buffered RGB window
515   if (vi_double_buffer) {                         396   if (vi_double_buffer) {
516     vi_stored = vi_double_buffer;                 397     vi_stored = vi_double_buffer;
517     attributeList = dblBuf_RGBA;                  398     attributeList = dblBuf_RGBA;
518   }                                               399   }
519                                                   400 
520   if (!vi_immediate || !vi_stored) {              401   if (!vi_immediate || !vi_stored) {
521     G4cout <<                                     402     G4cout <<
522     "G4OpenGLXViewer::G4OpenGLXViewer: unable     403     "G4OpenGLXViewer::G4OpenGLXViewer: unable to get required visuals."
523      << G4endl;                                   404      << G4endl;
524     fViewId = -1;  // This flags an error.        405     fViewId = -1;  // This flags an error.
525   }                                               406   }
526                                                   407 
527   //  glClearColor (0., 0., 0., 0.);              408   //  glClearColor (0., 0., 0., 0.);
528   //  glClearDepth (1.);                          409   //  glClearDepth (1.);
529 }                                                 410 }
530                                                   411 
531 G4OpenGLXViewer::~G4OpenGLXViewer () {            412 G4OpenGLXViewer::~G4OpenGLXViewer () {
532   if (fViewId >= 0) {                             413   if (fViewId >= 0) {
533     //Close a window from here                    414     //Close a window from here
534     glXMakeCurrent (dpy, None, NULL);             415     glXMakeCurrent (dpy, None, NULL);
535     glXDestroyContext (dpy, cxMaster);         << 416     glXDestroyContext (dpy, cx);
536     if (win) XDestroyWindow (dpy, win); // ...    417     if (win) XDestroyWindow (dpy, win); // ...if already deleted in
537     // sub-class G4OpenGLXmViewer.                418     // sub-class G4OpenGLXmViewer.
538     // We should do a XFreeColormap(dpy,cmap); << 
539     XFlush (dpy);                                 419     XFlush (dpy);
540   }                                               420   }
541 }                                                 421 }
542                                                   422   
                                                   >> 423 
                                                   >> 424 #endif
543                                                   425