38#include <Inventor/elements/SoViewportRegionElement.h>
39#include <Inventor/errors/SoDebugError.h>
41#include <Inventor/system/gl.h>
52 static bool first =
true;
60 const SbViewportRegion& aViewPortRegion
62:SoGLRenderAction(aViewPortRegion)
67,fProducer(
"HEPVis::SoGL2PSAction")
88 fFileName = aFileName;
97 fProducer = aProducer;
113 SoDebugError::post(
"SoGL2PSAction::enableFileWriting",
114 "openFile() failed for fil %s",
120 const SbViewportRegion& vpr = getViewportRegion();
121 SoViewportRegionElement::set(getState(),vpr);
122 SbVec2s origin = vpr.getViewportOriginPixels();
123 SbVec2s size = vpr.getViewportSizePixels();
124 if(!beginPage(origin[0],origin[1],size[0],size[1])) {
125 SoDebugError::post(
"SoGL2PSAction::enableFileWriting",
"beginPage() failed");
151 if(fContext && fFile) {
153 const SbViewportRegion& vpr = getViewportRegion();
154 SoViewportRegionElement::set(getState(),vpr);
155 SbVec2s origin = vpr.getViewportOriginPixels();
156 SbVec2s size = vpr.getViewportSizePixels();
157 if(!beginPage(origin[0],origin[1],size[0],size[1])) {
158 SoDebugError::post(
"SoGL2PSAction::beginTraversal",
"beginPage() failed");
163 SoDebugError::post(
"SoGL2PSAction::beginTraversal",
"endPage() failed");
167 SoGLRenderAction::beginTraversal(aNode);
170 SoGLRenderAction::beginTraversal(aNode);
174#include <tools/gl2ps>
177bool SoGL2PSAction::openFile()
186 ::tools_gl2psDeleteContext(fContext);
190 fContext = ::tools_gl2psCreateContext();
191 if(!fContext)
return false;
205 ::tools_gl2ps_set_gl_funcs(fContext,&_funcs);
207 fFile = ::fopen(fFileName.c_str(),
"wb");
209 ::tools_gl2psDeleteContext(fContext);
218void SoGL2PSAction::closeFile()
227 ::tools_gl2psDeleteContext(fContext);
233bool SoGL2PSAction::beginPage(
int a_x,
int a_y,
int a_w,
int a_h)
237 if(!fContext)
return false;
238 if(!fFile)
return false;
240 if( (a_w<=0) || (a_h<=0) )
return false;
257 (fContext,fTitle.c_str(),fProducer.c_str(),
258 vp,fFormat,sort,options,
TOOLS_GL_RGBA,0, NULL,0,0,0,
259 bufferSize,fFile,fFileName.c_str());
269bool SoGL2PSAction::endPage()
275 _status = ::tools_gl2psEndPage(fContext);
293 if(!fContext)
return false;
295 ::glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID,&valid);
296 if(!valid)
return false;
298 ::glGetFloatv(GL_CURRENT_RASTER_POSITION,pos);
299 int xoff = -(int)(aXmove + aXorig);
300 int yoff = -(int)(aYmove + aYorig);
301 int x = (int)(pos[0] + xoff);
302 int y = (int)(pos[1] + yoff);
305 ::glGetIntegerv(GL_VIEWPORT,vp);
308 if(x+w>(vp[0]+vp[2])) w = vp[0]+vp[2]-x;
309 if(y+h>(vp[1]+vp[3])) h = vp[1]+vp[3]-y;
311 if(s<=0)
return false;
312 float* image = (
float*)::malloc(s *
sizeof(
float));
313 if(!image)
return false;
314 ::glReadPixels(x,y,w,h,GL_RGB,GL_FLOAT,image);
315 GLint status = ::tools_gl2psDrawPixels(fContext,w,h,xoff,yoff,GL_RGB,GL_FLOAT,image);
void setExportImageFormat_TEX()
bool enableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
SoGL2PSAction(const SbViewportRegion &)
void setExportImageFormat_SVG()
void setExportImageFormat_EPS()
virtual ~SoGL2PSAction()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setExportImageFormat_PS()
void setExportImageFormat_PGF()
bool addBitmap(int, int, float=0, float=0, float=0, float=0)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
virtual void beginTraversal(SoNode *)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void disableFileWriting()
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setTitleAndProducer(const std::string &, const std::string &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setFileName(const std::string &)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
void setExportImageFormat_PDF()
#define TOOLS_GL2PS_USE_CURRENT_VIEWPORT
#define TOOLS_GL2PS_ERROR
#define TOOLS_GL2PS_SUCCESS
tools_GLint(* tools_glRenderMode_func)(tools_GLenum)
#define TOOLS_GL2PS_BEST_ROOT
#define TOOLS_GL2PS_BSP_SORT
void(* tools_glVertex3f_func)(tools_GLfloat, tools_GLfloat, tools_GLfloat)
void(* tools_glGetFloatv_func)(tools_GLenum, tools_GLfloat *)
void(* tools_glBegin_func)(tools_GLenum)
void(* tools_glFeedbackBuffer_func)(tools_GLsizei, tools_GLenum, tools_GLfloat *)
void(* tools_glPassThrough_func)(tools_GLfloat)
#define TOOLS_GL2PS_BLEND
void(* tools_glGetBooleanv_func)(tools_GLenum, tools_GLboolean *)
void(* tools_glEnd_func)()
#define TOOLS_GL2PS_OVERFLOW
void(* tools_glGetIntegerv_func)(tools_GLenum, tools_GLint *)
tools_GLboolean(* tools_glIsEnabled_func)(tools_GLenum)
#define TOOLS_GL2PS_DRAW_BACKGROUND