50#include <X11/Xmu/StdCmap.h>
76#define NewString(str) \
77 ((str) != 0 ? (strncpy((char*)malloc((unsigned)strlen(str) + 1), str, (unsigned)strlen(str) + 1)) : (char*)0)
79#define USE_DEFAULT_COLORMAP 1
80#define USE_STANDARD_COLORMAP 0
87 return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
96 glXMakeCurrent (
dpy,
win, cxVisSubThread);
105#ifdef G4MULTITHREADED
119 "Window activated for picking (left-mouse), exit (middle-mouse)."
124 if (
event.type == ButtonPress &&
event.xbutton.button == 1) {
127 else if (
event.type == ButtonPress &&
event.xbutton.button == 2)
break;
129 std::this_thread::sleep_for(std::chrono::milliseconds(100));
134#ifdef G4MULTITHREADED
136void G4OpenGLXViewer::SwitchToVisSubThread()
140 glXMakeCurrent (
dpy,
win, cxVisSubThread);
143void G4OpenGLXViewer::SwitchToMasterThread()
148 glXDestroyContext (
dpy, cxVisSubThread);
155 dpy = XOpenDisplay (0);
158 G4cerr <<
"G4OpenGLXViewer::G4OpenGLXViewer couldn't open display." <<
G4endl;
165 G4cerr <<
"G4OpenGLXViewer::G4OpenGLXViewer X Server has no GLX extension."
176 if (!XGetWindowAttributes(
dpy, XRootWindow (
dpy,
vi -> screen), &
xwa)) {
178 G4cerr <<
"G4OpenGLXViewer::G4OpenGLXViewer couldn't return window attributes"
187 G4cerr <<
"G4OpenGLXViewer::G4OpenGLXViewer couldn't create context."
197 status = XmuLookupStandardColormap (
dpy,
207 XStandardColormap* standardCmaps = XAllocStandardColormap ();
208 status = XGetRGBColormaps (
dpy,
209 XRootWindow (
dpy,
vi -> screen),
214 for (i = 0; i < numCmaps; i++) {
215 if (standardCmaps[i].visualid ==
vi -> visualid) {
216 cmap = standardCmaps[i].colormap;
221 XFree (standardCmaps);
230 XRootWindow(
dpy,
vi -> screen),
241 XRootWindow(
dpy,
vi -> screen),
254 G4cout <<
"G4OpenGLXViewer::G4OpenGLXViewer failed to allocate a Colormap."
265 swa.border_pixel = 0;
266 swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
267 swa.backing_store = WhenMapped;
300 XStringListToTextProperty (&window_name, 1, &
windowName);
301 XStringListToTextProperty (&icon_name, 1, &
iconName);
303 wm_hints -> initial_state = NormalState;
306 wm_hints -> flags = StateHint | IconPixmapHint | InputHint;
311 win = XCreateWindow (
dpy, XRootWindow (
dpy,
vi -> screen), x_origin,
313 InputOutput,
vi -> visual,
314 CWBorderPixel | CWColormap |
315 CWEventMask | CWBackingStore,
331 G4cerr <<
"G4OpenGLXViewer::G4OpenGLXViewer failed to attach a GLX context."
333 GLint
error = GL_NO_ERROR;
334 while ((
error = glGetError()) != GL_NO_ERROR) {
336 case GL_INVALID_ENUM :
338 case GL_INVALID_VALUE :
340 case GL_INVALID_OPERATION :
341 G4cout <<
"GL Error: GL_INVALID_OPERATION" <<
G4endl;
break;
342 case GL_OUT_OF_MEMORY :
344 case GL_STACK_UNDERFLOW :
345 G4cout <<
"GL Error: GL_STACK_UNDERFLOW" <<
G4endl;
break;
346 case GL_STACK_OVERFLOW :
347 G4cout <<
"GL Error: GL_STACK_OVERFLOW" <<
G4endl;
break;
358 std::map<G4double,G4String> fonts;
359 fonts[10.] =
"-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1";
360 fonts[11.] =
"-adobe-courier-bold-r-normal--11-80-100-100-m-60-iso8859-1";
361 fonts[12.] =
"-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1";
362 fonts[13.] =
"fixed";
363 fonts[14.] =
"-adobe-courier-bold-r-normal--14-100-100-100-m-90-iso8859-1";
364 fonts[17.] =
"-adobe-courier-bold-r-normal--17-120-100-100-m-100-iso8859-1";
365 fonts[18.] =
"-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1";
366 fonts[20.] =
"-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1";
367 fonts[24.] =
"-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1";
368 fonts[25.] =
"-adobe-courier-bold-r-normal--25-180-100-100-m-150-iso8859-1";
369 fonts[34.] =
"-adobe-courier-bold-r-normal--34-240-100-100-m-200-iso8859-1";
370 std::map<G4double,G4String>::const_iterator i;
371 for (i = fonts.begin(); i != fonts.end(); ++i) {
372 XFontStruct* font_info = XLoadQueryFont(
dpy, i->second);
375 "G4OpenGLXViewer::CreateFontLists XLoadQueryFont failed for font\n "
380 G4int font_base = glGenLists(256);
383 "G4OpenGLXViewer::CreateFontLists out of display lists for fonts."
387 G4int first = font_info->min_char_or_byte2;
388 G4int last = font_info->max_char_or_byte2;
389 glXUseXFont(font_info->fid, first, last-first+1, font_base + first);
390 G4int width = font_info->max_bounds.width;
392 (
this, font_base, i->first, i->second, width);
410 static G4int callCount = 0;
413 if (callCount <= 1) {
415 "G4OpenGLXViewer::DrawText: No fonts available for \""
430 const char* textCString = textString.c_str();
435 glPushAttrib(GL_LIST_BIT);
451 glBitmap(0,0,0,0,xmove,ymove,0);
455 glCallLists(strlen(textCString),GL_UNSIGNED_BYTE,(GLubyte*)textCString);
494 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
495 "\n Working with a single buffer."
501 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a single buffer visual."
506 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
533 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get required visuals."
545 glXMakeCurrent (
dpy, None, NULL);
static Bool G4OpenGLXViewerWaitForNotify(Display *, XEvent *e, char *arg)
static G4String Status(G4StepStatus stps)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4double GetAlpha() const
G4double GetGreen() const
static void AddFontBase(G4VViewer *, G4int fontBase, G4double size, const G4String &fontName, G4int width)
static const FontInfo & GetFontInfo(G4VViewer *, G4double size)
unsigned int getWinHeight() const
void ResizeWindow(unsigned int, unsigned int)
unsigned int getWinWidth() const
virtual void DrawText(const G4Text &)
virtual G4String Pick(GLdouble x, GLdouble y)
static int snglBuf_RGBA[12]
static int dblBuf_RGBA[13]
virtual ~G4OpenGLXViewer()
static XVisualInfo * vi_double_buffer
void CreateGLXContext(XVisualInfo *vi)
virtual void CreateFontLists()
void DrawText(const G4Text &)
static XVisualInfo * vi_single_buffer
XVisualInfo * vi_immediate
G4OpenGLXViewer(G4OpenGLSceneHandler &scene)
virtual void CreateMainWindow()
G4double GetYOffset() const
G4double GetXOffset() const
G4Point3D GetPosition() const
const G4Colour & GetTextColour(const G4Text &)
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
G4VSceneHandler & fSceneHandler
bool IsWindowLocationHintY() const
G4int GetWindowAbsoluteLocationHintY(G4int) const
bool IsWindowLocationHintX() const
unsigned int GetWindowSizeHintX() const
bool IsWindowSizeHintX() const
G4int GetWindowAbsoluteLocationHintX(G4int) const
unsigned int GetWindowSizeHintY() const
static Verbosity GetVerbosity()
static PROLOG_HANDLER error