00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifdef G4VIS_BUILD_OPENGL_DRIVER
00032 #define G4VIS_BUILD_OPENGL_GL2PS
00033 #endif
00034 #ifdef G4VIS_BUILD_OI_DRIVER
00035 #define G4VIS_BUILD_OPENGL_GL2PS
00036 #endif
00037
00038 #ifdef G4VIS_BUILD_OPENGL_GL2PS
00039
00040 #include "G4OpenGL2PSAction.hh"
00041
00042
00043 G4OpenGL2PSAction::G4OpenGL2PSAction(
00044 )
00047 {
00048 fFileName = "";
00049 fFile = 0;
00050 fViewport[0] = 0;
00051 fViewport[1] = 0;
00052 fViewport[2] = 0;
00053 fViewport[3] = 0;
00054 fBufferSize = 1024;
00055 fBufferSizeLimit = 8192;
00056 resetBufferSizeParameters();
00057 }
00058
00060 void G4OpenGL2PSAction::resetBufferSizeParameters(
00061 )
00064 {
00065 fBufferSize = 1024;
00066 fBufferSizeLimit = 8192;
00067 }
00068
00070 void G4OpenGL2PSAction::setLineWidth(
00071 int width
00072 )
00075 {
00076 gl2psLineWidth( width );
00077 }
00078
00080 void G4OpenGL2PSAction::setPointSize(
00081 int size
00082 )
00085 {
00086 gl2psPointSize( size );
00087 }
00088
00090 void G4OpenGL2PSAction::setViewport(
00091 int a
00092 ,int b
00093 ,int winSizeX
00094 ,int winSizeY
00095 )
00098 {
00099 fViewport[0] = a;
00100 fViewport[1] = b;
00101 fViewport[2] = winSizeX;
00102 fViewport[3] = winSizeY;
00103 }
00104
00106 void G4OpenGL2PSAction::setFileName(
00107 const char* aFileName
00108 )
00111 {
00112 fFileName = aFileName;
00113 }
00115 bool G4OpenGL2PSAction::enableFileWriting(
00116 )
00119 {
00120 fFile = ::fopen(fFileName,"wb");
00121 if(!fFile) {
00122 return false;
00123 }
00124 return G4gl2psBegin();
00125 }
00127 bool G4OpenGL2PSAction::disableFileWriting(
00128 )
00131 {
00132 int state = gl2psEndPage();
00133 ::fclose(fFile);
00134 if (state == GL2PS_OVERFLOW) {
00135 return false;
00136 }
00137 fFile = 0;
00138 return true;
00139 }
00141 bool G4OpenGL2PSAction::extendBufferSize(
00142 )
00145 {
00146
00147 if (fBufferSize*2 <= fBufferSizeLimit) {
00148 fBufferSize = fBufferSize*2;
00149 return true;
00150 }
00151 return false;
00152 }
00154 bool G4OpenGL2PSAction::fileWritingEnabled(
00155 ) const
00158 {
00159 return (fFile?true:false);
00160 }
00162 bool G4OpenGL2PSAction::G4gl2psBegin(
00163 )
00166 {
00167 if(!fFile) return false;
00168 int options = GL2PS_OCCLUSION_CULL |
00169 GL2PS_BEST_ROOT | GL2PS_SILENT | GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT;
00170
00171
00172 int sort = GL2PS_BSP_SORT;
00173
00174 GLint buffsize = 0;
00175 buffsize += fBufferSize*fBufferSize;
00176
00177 glGetIntegerv(GL_VIEWPORT,fViewport);
00178
00179 GLint res = gl2psBeginPage("title","HEPVis::G4OpenGL2PSAction",
00180 fViewport,
00181 GL2PS_EPS,
00182 sort,
00183 options,
00184 GL_RGBA,0, NULL,0,0,0,
00185 buffsize,
00186 fFile,fFileName);
00187 if (res == GL2PS_ERROR) {
00188 return false;
00189 }
00190 return true;
00191
00192 }
00193
00194
00195
00196
00197 #endif