26 #ifdef G4VIS_BUILD_OI_DRIVER
36 #include <HEPVis/actions/SoGL2PSAction.h>
39 #include <Inventor/elements/SoViewportRegionElement.h>
40 #include <Inventor/errors/SoDebugError.h>
42 #include "Geant4_gl2ps.h"
46 SO_ACTION_SOURCE(SoGL2PSAction)
48 void SoGL2PSAction::initClass(
53 SO_ACTION_INIT_CLASS(SoGL2PSAction,SoGLRenderAction);
56 SoGL2PSAction::SoGL2PSAction(
57 const SbViewportRegion& aViewPortRegion
59 :SoGLRenderAction(aViewPortRegion)
64 setFileName(
"out.ps");
65 SO_ACTION_CONSTRUCTOR(SoGL2PSAction);
68 bool SoGL2PSAction::enableFileWriting(
73 fFile = ::fopen(fFileName,
"w");
75 SoDebugError::post(
"SoGL2PSAction::enableFileWriting",
76 "Cannot open file %s",fFileName);
81 const SbViewportRegion& vpr = getViewportRegion();
82 SoViewportRegionElement::set(getState(),vpr);
88 void SoGL2PSAction::disableFileWriting(
102 bool SoGL2PSAction::addBitmap(
113 if(!fFile)
return false;
115 glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
116 if(!valid)
return false;
118 glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
119 int xoff = -(int)(aXmove + aXorig);
120 int yoff = -(int)(aYmove + aYorig);
121 int x = (int)(pos[0] + xoff);
122 int y = (int)(pos[1] + yoff);
125 glGetIntegerv(GL_VIEWPORT,vp);
128 if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
129 if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
131 if(s<=0)
return false;
132 float* image = (
float*)::malloc(s *
sizeof(
float));
133 if(!image)
return false;
134 glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
135 GLint status = gl2psDrawPixels(w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
137 return (status!=GL2PS_SUCCESS ?
false :
true);
140 void SoGL2PSAction::beginTraversal(
148 const SbViewportRegion& vpr = getViewportRegion();
149 SoViewportRegionElement::set(getState(),vpr);
155 SoGLRenderAction::beginTraversal(aNode);
159 SoGLRenderAction::beginTraversal(aNode);
static const G4double pos