source: trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc @ 896

Last change on this file since 896 was 896, checked in by garnier, 16 years ago

Modif pour XGeometry complet. Avec debug

  • Property svn:mime-type set to text/cpp
File size: 19.0 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: G4OpenGLXViewer.cc,v 1.42 2007/05/25 10:47:17 allison Exp $
28// GEANT4 tag $Name: HEAD $
29//
30//
31// Andrew Walkden  7th February 1997
32// G4OpenGLXViewer : Class to provide XWindows specific
33//                 functionality for OpenGL in GEANT4
34
35#ifdef G4VIS_BUILD_OPENGLX_DRIVER
36
37#include "G4OpenGLXViewer.hh"
38
39#include "G4OpenGLFontBaseStore.hh"
40
41#include <sstream>
42
43#include "G4VisExtent.hh"
44#include "G4LogicalVolume.hh"
45#include "G4VSolid.hh"
46#include "G4Point3D.hh"
47#include "G4Normal3D.hh"
48
49#include <X11/Xatom.h>
50#include <X11/Xutil.h>
51
52#include <assert.h>
53
54int G4OpenGLXViewer::snglBuf_RGBA[12] =
55{ GLX_RGBA,
56  GLX_RED_SIZE, 1,
57  GLX_GREEN_SIZE, 1,
58  GLX_BLUE_SIZE, 1,
59  GLX_DEPTH_SIZE, 1,
60  GLX_STENCIL_SIZE, 1,
61  None };
62
63int G4OpenGLXViewer::dblBuf_RGBA[13] =
64{ GLX_RGBA,
65  GLX_RED_SIZE, 1,
66  GLX_GREEN_SIZE, 1,
67  GLX_BLUE_SIZE, 1,
68  GLX_DOUBLEBUFFER,
69  GLX_DEPTH_SIZE, 1,
70  GLX_STENCIL_SIZE, 1,
71  None };
72
73#define NewString(str) \
74 ((str) != NULL ? (strcpy((char*)malloc((unsigned)strlen(str) + 1), str)) : (char*)NULL)
75
76#define USE_DEFAULT_COLORMAP 1
77#define USE_STANDARD_COLORMAP 0
78
79XVisualInfo*  G4OpenGLXViewer::vi_single_buffer = 0;
80XVisualInfo*  G4OpenGLXViewer::vi_double_buffer = 0;
81
82extern "C" {
83  static Bool G4OpenGLXViewerWaitForNotify (Display*, XEvent* e, char* arg) {
84    return (e->type == MapNotify) && (e->xmap.window == (Window) arg);
85  }
86}
87
88void G4OpenGLXViewer::SetView () {
89  glXMakeCurrent (dpy, win, cx);
90  G4OpenGLViewer::SetView (); 
91}
92
93void G4OpenGLXViewer::ShowView () {
94  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
95                //be propagated before progressing.
96  glFlush ();
97
98  if (fVP.IsPicking()) {
99    G4cout <<
100      "Window activated for picking (left-mouse), exit (middle-mouse)."
101           << G4endl;
102    while (true) {
103      if (XPending(dpy)) {
104        XNextEvent(dpy, &event);
105        if (event.type == ButtonPress && event.xbutton.button == 1) {
106          Pick(event.xbutton.x, event.xbutton.y);
107        }
108        else if (event.type == ButtonPress && event.xbutton.button == 2) break;
109      }
110    }
111  }
112}
113
114void G4OpenGLXViewer::GetXConnection () {
115// get a connection.
116  dpy = XOpenDisplay (0);
117  if (!dpy) {
118    fViewId = -1;  // This flags an error.
119    G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't open display." << G4endl;
120    return;
121  }
122
123// make sure OpenGL is supported and installed properly.
124  if (!glXQueryExtension (dpy, &errorBase, &eventBase)) {
125    fViewId = -1;  // This flags an error.
126    G4cerr << "G4OpenGLViewer::G4OpenGLViewer X Server has no GLX extension."
127         << G4endl;
128    return;
129  }
130
131}
132
133void G4OpenGLXViewer::CreateGLXContext (XVisualInfo* v) {
134
135  vi = v;
136// get window's attributes
137  if (!XGetWindowAttributes(dpy, XRootWindow (dpy, vi -> screen), &xwa)) {
138    fViewId = -1;  // This flags an error.
139    G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't return window attributes"
140         << G4endl;
141    return;
142  }
143 
144// create a GLX context
145  cx = glXCreateContext (dpy, vi, 0, true);
146  if (!cx) {
147    fViewId = -1;  // This flags an error.
148    G4cerr << "G4OpenGLViewer::G4OpenGLViewer couldn't create context."
149         << G4endl;
150    return;
151  }
152
153// New stab at getting a colormap
154
155  Status status;
156  XStandardColormap *standardCmaps = XAllocStandardColormap ();
157  int i, numCmaps;
158
159  status = XmuLookupStandardColormap (dpy,
160                                      vi -> screen,
161                                      vi -> visualid,
162                                      vi -> depth,
163                                      XA_RGB_DEFAULT_MAP,
164                                      False,
165                                      True);
166 
167  if (status == 1) {
168    cmap = 0;
169    status = XGetRGBColormaps (dpy,
170                               XRootWindow (dpy, vi -> screen),
171                               &standardCmaps,
172                               &numCmaps,
173                               XA_RGB_DEFAULT_MAP);
174    if (status == 1)
175      for (i = 0; i < numCmaps; i++) {
176        if (standardCmaps[i].visualid == vi -> visualid) {
177          cmap = standardCmaps[i].colormap;
178          XFree (standardCmaps);
179          break;
180        }
181      }
182    if (!cmap) {
183      fViewId = -1;  // This flags an error.
184      G4cerr <<
185   "G4OpenGLViewer::G4OpenGLViewer failed to allocate a standard colormap."
186             << G4endl;
187      return;
188    }
189    G4cout << "Got standard cmap" << G4endl;
190  } else {
191    cmap = XCreateColormap (dpy,
192                            XRootWindow(dpy, vi -> screen),
193                            vi -> visual,
194                            AllocNone);
195    G4cout << "Created own cmap" << G4endl;
196  }
197
198  if (!cmap) {
199    fViewId = -1;  // This flags an error.
200    G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to allocate a Colormap."
201         << G4endl;
202    return;
203  }
204
205}
206 
207void G4OpenGLXViewer::CreateMainWindow () {
208 
209// create a window
210  swa.colormap = cmap;
211  swa.border_pixel = 0;
212  swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask;
213  swa.backing_store = WhenMapped;
214
215  // Window size and position...
216  unsigned int width, height;
217  x_origin = 0;
218  y_origin = 0;
219  size_hints = XAllocSizeHints();
220
221  // already done in G4VViewer at creation
222
223//   const G4String& XGeometryString = fVP.GetXGeometryString();
224//   int screen_num = DefaultScreen(dpy);
225//   if (!XGeometryString.empty()) {
226//     G4int geometryResultMask = XParseGeometry
227//       ((char*)XGeometryString.c_str(),
228//        &x_origin, &y_origin, &width, &height);
229//     if (geometryResultMask & (WidthValue | HeightValue)) {
230//       if (geometryResultMask & XValue) {
231//      if (geometryResultMask & XNegative) {
232//        x_origin = DisplayWidth(dpy, screen_num) + x_origin - width;
233//      }
234//      size_hints->flags |= PPosition;
235//      size_hints->x = x_origin;
236//       }
237//       if (geometryResultMask & YValue) {
238//      if (geometryResultMask & YNegative) {
239//        y_origin = DisplayHeight(dpy, screen_num) + y_origin - height;
240//      }
241//      size_hints->flags |= PPosition;
242//      size_hints->y = y_origin;
243//       }
244//     } else {
245//       G4cout << "ERROR: Geometry string \""
246//           << XGeometryString
247//           << "\" invalid.  Using \"600x600\"."
248//           << G4endl;
249//       width = 600;
250//       height = 600;
251//     }
252//   }
253//  size_hints->width = width;
254//  size_hints->height = height;
255
256#ifdef G4DEBUG
257  printf("G4OpenGLXViewer::CreateMainWindow CreateWindow Mauvais Size:W:%d X:%d H:%d Y:%d \n",width,fVP.GetWindowSizeHintX(),height, fVP.GetWindowSizeHintY());
258#endif
259
260
261  Window root_return;
262  int x_return, y_return;
263  unsigned int width_return, height_return;
264  unsigned int border_width_return;
265  unsigned int depth_return;
266 
267#ifdef G4DEBUG
268  printf("G4OpenGLXViewer::CreateMainWindow 1\n");
269#endif
270  // get the parent window's geometry
271  XGetGeometry(dpy, XRootWindow (dpy, vi -> screen), &root_return, &x_return, &y_return,
272               &width_return, &height_return, &border_width_return,
273               &depth_return);
274 
275#ifdef G4DEBUG
276  printf("G4OpenGLXViewer::CreateMainWindow 2 root W :%d H :%d\n",width_return, height_return);
277#endif
278
279  //  G4int                             WinSize_x;
280  //  G4int                             WinSize_y;
281  WinSize_x = fVP.GetWindowSizeHintX();
282  WinSize_y = fVP.GetWindowSizeHintY();
283  x_origin = fVP.GetWindowAbsoluteLocationHintX(width_return);
284  y_origin = fVP.GetWindowAbsoluteLocationHintY(height_return);
285
286  size_hints->base_width = WinSize_x;
287  size_hints->base_height = WinSize_y;
288  size_hints->x = x_origin;
289  size_hints->y = y_origin;
290  size_hints->flags |= PSize | PPosition;
291#ifdef G4DEBUG
292  printf("G4OpenGLXViewer::CreateMainWindow CreateWindow Size:W:%d H:%d X:%d Y:%d \n",WinSize_x,WinSize_y,x_origin,y_origin);
293#endif
294
295  G4cout << "Window name: " << fName << G4endl;
296  strncpy (charViewName, fName, 100);
297  char *window_name = charViewName;
298  char *icon_name = charViewName;
299  //char tmpatom[] = "XA_WM_NORMAL_HINTS";
300  wm_hints = XAllocWMHints();
301  class_hints = XAllocClassHint();
302
303  XStringListToTextProperty (&window_name, 1, &windowName);
304  XStringListToTextProperty (&icon_name, 1, &iconName);
305
306  wm_hints -> initial_state = NormalState;
307  wm_hints -> input = True;
308  wm_hints -> icon_pixmap = icon_pixmap;
309  wm_hints -> flags = StateHint | IconPixmapHint | InputHint;
310
311  class_hints -> res_name  = NewString("G4OpenGL");
312  class_hints -> res_class = NewString("G4OpenGL");
313
314   win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin,
315                        y_origin, WinSize_x, WinSize_y, 0, vi -> depth,
316                        InputOutput, vi -> visual, 
317                        CWBorderPixel | CWColormap |
318                        CWEventMask | CWBackingStore,
319                        &swa);
320 
321   XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0,
322                     size_hints, wm_hints, class_hints);
323 
324// request X to Draw window on screen.
325  XMapWindow (dpy, win);
326
327// Wait for window to appear (wait for an "expose" event).
328  XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win);
329
330// connect the context to a window
331  Bool success = glXMakeCurrent (dpy, win, cx);
332  if (!success) {
333    fViewId = -1;  // This flags an error.
334    G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to attach a GLX context."
335         << G4endl;
336    GLint error = GL_NO_ERROR;
337    while ((error = glGetError()) != GL_NO_ERROR) {
338      G4cout << "GL Error: " << gluErrorString(error) << G4endl;
339    }
340    return;
341  }
342
343}
344
345void G4OpenGLXViewer::CreateFontLists () {
346
347  std::map<G4double,G4String> fonts;  // G4VMarker screen size and font name.
348  fonts[10.] = "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1";
349  fonts[11.] = "-adobe-courier-bold-r-normal--11-80-100-100-m-60-iso8859-1";
350  fonts[12.] = "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1";
351  fonts[13.] = "fixed";
352  fonts[14.] = "-adobe-courier-bold-r-normal--14-100-100-100-m-90-iso8859-1";
353  fonts[17.] = "-adobe-courier-bold-r-normal--17-120-100-100-m-100-iso8859-1";
354  fonts[18.] = "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1";
355  fonts[20.] = "-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1";
356  fonts[24.] = "-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1";
357  fonts[25.] = "-adobe-courier-bold-r-normal--25-180-100-100-m-150-iso8859-1";
358  fonts[34.] = "-adobe-courier-bold-r-normal--34-240-100-100-m-200-iso8859-1";
359  std::map<G4double,G4String>::const_iterator i;
360  for (i = fonts.begin(); i != fonts.end(); ++i) {
361    XFontStruct* font_info = XLoadQueryFont(dpy, i->second);
362    if (!font_info) {
363      G4cerr <<
364        "G4OpenGLXViewer: XLoadQueryFont failed for font\n  "
365             << i->second
366             << G4endl;
367      continue;
368    }
369    G4int font_base = glGenLists(256);
370    if (!font_base) {
371      G4cerr << "G4OpenGLXViewer: out of display lists for fonts."
372             << G4endl;
373      continue;
374    }
375    G4int first = font_info->min_char_or_byte2;
376    G4int last  = font_info->max_char_or_byte2;
377    glXUseXFont(font_info->fid, first, last-first+1,font_base+first);
378    G4OpenGLFontBaseStore::AddFontBase(this,font_base,i->first,i->second);
379  }
380}
381
382G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLSceneHandler& scene):
383G4VViewer (scene, -1),
384G4OpenGLViewer (scene),
385vi_immediate (0),
386vi_stored (0),
387vi (0),
388cmap (0)
389{
390  GetXConnection ();
391  if (fViewId < 0) return;
392 
393  // Try for a visual suitable for OpenGLImmediate..
394  // first try for a single buffered RGB window
395  if (!vi_single_buffer) {
396    vi_single_buffer =
397      glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA);
398  }
399  if (!vi_double_buffer) {
400    vi_double_buffer =
401      glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA);
402  }
403
404  if (vi_single_buffer || vi_double_buffer) {
405    if (!vi_double_buffer) {
406      G4cout <<
407        "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
408        "\n  Working with a single buffer."
409             << G4endl;
410    }
411  } else {
412    if (!vi_single_buffer) {
413      G4cout <<
414        "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a single buffer visual."
415             << G4endl;
416    }
417    if (!vi_double_buffer) {
418      G4cout <<
419        "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual."
420             << G4endl;
421    }
422  }
423
424  if (vi_single_buffer) {
425    vi_immediate = vi_single_buffer;
426    attributeList = snglBuf_RGBA;
427  }
428 
429  if (!vi_immediate){
430    // next try for a double buffered RGB, but Draw to top buffer
431    if (vi_double_buffer) {
432      vi_immediate = vi_double_buffer;
433      attributeList = dblBuf_RGBA;
434    }
435  }
436
437  // Now try for a visual suitable for OpenGLStored...
438  // Try for a double buffered RGB window
439  if (vi_double_buffer) {
440    vi_stored = vi_double_buffer;
441    attributeList = dblBuf_RGBA;
442  }
443
444  if (!vi_immediate || !vi_stored) {
445    G4cout <<
446    "G4OpenGLXViewer::G4OpenGLXViewer: unable to get required visuals."
447           << G4endl;
448    fViewId = -1;  // This flags an error.
449  }
450
451  //  glClearColor (0., 0., 0., 0.);
452  //  glClearDepth (1.);
453}
454
455G4OpenGLXViewer::~G4OpenGLXViewer () {
456  if (fViewId >= 0) {
457    //Close a window from here
458    glXMakeCurrent (dpy, None, NULL);
459    glXDestroyContext (dpy, cx);
460    if (win) XDestroyWindow (dpy, win); // ...if already deleted in
461    // sub-class G4OpenGLXmViewer.
462    XFlush (dpy);
463  }
464}
465
466void G4OpenGLXViewer::print() {
467 
468  //using namespace std;
469  //cout << "print_col_callback requested with file name: " << print_string << G4endl;
470 
471  if (vectored_ps) {
472
473    G4OpenGLViewer::print();
474
475  } else {
476
477    XVisualInfo* pvi;
478    GLXContext pcx = create_GL_print_context(pvi);
479
480    if (!pcx) {
481      G4cout << "Unable to create print context." << G4endl;
482      return;
483    }
484
485    GLXContext tmp_cx;
486    tmp_cx = cx;
487    cx=pcx;
488   
489    Pixmap pmap = XCreatePixmap (dpy,
490                                 XRootWindow (dpy, pvi->screen),
491                                 WinSize_x, WinSize_y,
492                                 pvi->depth);
493   
494    GLXPixmap glxpmap = glXCreateGLXPixmap (dpy,
495                                            pvi,
496                                            pmap);
497   
498    GLXDrawable tmp_win;
499    tmp_win=win;
500    win=glxpmap;
501   
502    glXMakeCurrent (dpy,
503                    win,
504                    cx);
505   
506    glViewport (0, 0, WinSize_x, WinSize_y);
507   
508    ClearView ();
509    SetView ();
510    DrawView ();
511   
512    generateEPS (print_string,
513                 print_colour,
514                 WinSize_x, WinSize_y);
515   
516    win=tmp_win;
517    cx=tmp_cx;
518   
519    glXMakeCurrent (dpy,
520                    win,
521                    cx);
522   
523  }
524
525}
526
527GLubyte* G4OpenGLXViewer::grabPixels (int inColor, unsigned int width, unsigned int height) {
528 
529  GLubyte* buffer;
530  GLint swapbytes, lsbfirst, rowlength;
531  GLint skiprows, skippixels, alignment;
532  GLenum format;
533  int size;
534
535  if (inColor) {
536    format = GL_RGB;
537    size = width*height*3;
538  } else {
539    format = GL_LUMINANCE;
540    size = width*height*1;
541  }
542
543  buffer = new GLubyte[size];
544  if (buffer == NULL)
545    return NULL;
546
547  glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);
548  glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);
549  glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength);
550
551  glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows);
552  glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels);
553  glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
554
555  glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
556  glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
557  glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
558
559  glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
560  glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
561  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
562
563  glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer);
564
565  glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes);
566  glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst);
567  glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength);
568 
569  glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows);
570  glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels);
571  glPixelStorei (GL_UNPACK_ALIGNMENT, alignment);
572 
573  return buffer;
574}
575
576int G4OpenGLXViewer::generateEPS (char* filnam,
577                                int inColour,
578                                unsigned int width,
579                                unsigned int height) {
580
581  FILE* fp;
582  GLubyte* pixels;
583  GLubyte* curpix;
584  int components, pos, i;
585
586  pixels = grabPixels (inColour, width, height);
587
588  if (pixels == NULL)
589    return 1;
590  if (inColour) {
591    components = 3;
592  } else {
593    components = 1;
594  }
595 
596  fp = fopen (filnam, "w");
597  if (fp == NULL) {
598    return 2;
599  }
600 
601  fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
602  fprintf (fp, "%%%%Title: %s\n", filnam);
603  fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");
604  fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height);
605  fprintf (fp, "%%%%EndComments\n");
606  fprintf (fp, "gsave\n");
607  fprintf (fp, "/bwproc {\n");
608  fprintf (fp, "    rgbproc\n");
609  fprintf (fp, "    dup length 3 idiv string 0 3 0 \n");
610  fprintf (fp, "    5 -1 roll {\n");
611  fprintf (fp, "    add 2 1 roll 1 sub dup 0 eq\n");
612  fprintf (fp, "    { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");
613  fprintf (fp, "       3 1 roll 5 -1 roll } put 1 add 3 0 \n");
614  fprintf (fp, "    { 2 1 roll } ifelse\n");
615  fprintf (fp, "    }forall\n");
616  fprintf (fp, "    pop pop pop\n");
617  fprintf (fp, "} def\n");
618  fprintf (fp, "systemdict /colorimage known not {\n");
619  fprintf (fp, "   /colorimage {\n");
620  fprintf (fp, "       pop\n");
621  fprintf (fp, "       pop\n");
622  fprintf (fp, "       /rgbproc exch def\n");
623  fprintf (fp, "       { bwproc } image\n");
624  fprintf (fp, "   }  def\n");
625  fprintf (fp, "} if\n");
626  fprintf (fp, "/picstr %d string def\n", width * components);
627  fprintf (fp, "%d %d scale\n", width, height);
628  fprintf (fp, "%d %d %d\n", width, height, 8);
629  fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height);
630  fprintf (fp, "{currentfile picstr readhexstring pop}\n");
631  fprintf (fp, "false %d\n", components);
632  fprintf (fp, "colorimage\n");
633 
634  curpix = (GLubyte*) pixels;
635  pos = 0;
636  for (i = width*height*components; i>0; i--) {
637    fprintf (fp, "%02hx ", *(curpix++));
638    if (++pos >= 32) {
639      fprintf (fp, "\n");
640      pos = 0;
641    }
642  }
643  if (pos)
644    fprintf (fp, "\n");
645
646  fprintf (fp, "grestore\n");
647  fprintf (fp, "showpage\n");
648  delete pixels;
649  fclose (fp);
650  return 0;
651}
652
653GLXContext G4OpenGLXViewer::create_GL_print_context(XVisualInfo*& pvi) {
654 
655  pvi = glXChooseVisual (dpy,
656                         XDefaultScreen (dpy),
657                         snglBuf_RGBA);
658
659  if (!pvi) {
660    pvi = glXChooseVisual (dpy,
661                           XDefaultScreen (dpy),
662                           dblBuf_RGBA);
663  }
664
665  return glXCreateContext (dpy,
666                           pvi,
667                           NULL,
668                           False);
669}
670
671#endif
Note: See TracBrowser for help on using the repository browser.